# Tag Info

### How to quickly make a rectangular array of continous 1 and 0 given the start position of 1

Obligatory bare-metal C answer for ultimate speed: ...
• 48k
Accepted

### Apply a function row- and columnwise

If we change dt to: ...
• 237k
Accepted

Dataset[dt, Alignment -> Right, Background -> {{"ita" | "por", "20" | "21" | "22"} -> GrayLevel[.9]}] ...
• 396k
Accepted

### The Battleship game: Identify objects within a matrix

NearestNeigborGraph + ConnectedComponents ...
• 396k

### How to quickly make a rectangular array of continous 1 and 0 given the start position of 1

This is pretty fast: ...
• 25.5k

### How to quickly make a rectangular array of continous 1 and 0 given the start position of 1

Instead of constructing every column separately, note that each column is contained in a vector of n 0's and n 1's, we only need to pick the corresponding part. For ease, we create the matrix row wise ...
• 52.7k
Accepted

### How can I change elements in a matrix to a combination of other elements?

A simple way would be to define a function to transform a single triple: transform[{x_, y_, z_}] := {x + Cos[z/x], y, z - Sin[z/x]} and then map it over your list: ...
• 29.1k

### Taxicab Geometry

Mathematica has a large set of graph functions. Here's a 10-by-10 graph of labeled nodes. We can use the graph to find every path that has a length of 9 between two nodes, and to display the paths. <...
• 5,225

### How can I build a symmetric matrix of up to 100?

Look up a Toeplitz matrix: m[n_] := a^(ToeplitzMatrix[n]-1) Alternatively, an explicit construction as a rule-based matrix: ...
• 48k

...
• 48k

...
• 19.4k

### Visualizing diagrams needed to compute $\operatorname{Tr}(A^3 (A^T)^3)$

Explanation why some graphs appear more than ones: It depends on the number of possible paths - some graphs have only one possibility, the graph below has four. Functions definitions: I borrowed <...
• 18.8k

...
• 55.4k
Accepted

### How to quickly make a rectangular array of continous 1 and 0 given the start position of 1

Plain C-style loop with Compile: ...

### How to set to 0 all terms in a matrix which contain a minus

F /. _?InternalSyntacticNegativeQ -> 0 {{β, x β}, {0, 0}} Also ...
• 396k
Accepted

### How to set to 0 all terms in a matrix which contain a minus

Why ReplaceAll[] fails: Since the proposed rules replace any negative by 0, when applied at all levels, we get things like ...
• 237k

### How can I change elements in a matrix to a combination of other elements?

Equivalent to @lericrs answer except a pure function is used rather than defining a helper function ...
• 159k

### How can I expand a matrix and fill in zeros?

See the docs for ArrayFlatten k = ArrayFlatten[{{m, 0}, {0, IdentityMatrix[2]}}]; k // MatrixForm \left( \...
• 12.6k

### How can I expand a matrix and fill in zeros?

BlockDiagonalMatrix[{m, IdentityMatrix[2]}] To get a "normal" matrix: ...
• 29.1k
Accepted

### Find a certain path through a matrix

Update 2: An alternative method using Fold: ...
• 396k

### The Battleship game: Identify objects within a matrix

SparseArray + FindClusters ...
• 396k

### Why is Mathematica not simplifying eigenvalues?

The trick is to move the exp inside the sqrt and use the double angle trig rule. A = {{x*Exp[I*y], z}, {z, x*Exp[(-I)*y]}} {v1, v2} = Eigenvalues[A] ...
• 145k

### Taxicab Geometry

Certainly a very wasteful method to generate all possible maths, but it's a start: ...

### Taxicab Geometry

Let's start with an abstraction: routes = Permutations[{up, up, up, up, right, right, right, right, right}]; We now have 126 paths to get from {2,5} to {7,9} by ...
• 29.1k

### Fast pairwise difference

As Henrik has demonstrated in his excellent answer, the good old C compiler interface is still super fast -- the fastest if considering the compiling time. But the new compiler (...
• 27.6k
Accepted

### Elegant way to write a system of ODEs with a Matrix

If you have your system as $x'=Ax+f$ then you can set it up as follows ...
• 145k
Accepted

### Replace a column/row of a matrix under a condition by a random number

Modify -> (Rule) to :> (RuleDelayed).
• 66.8k

### How can I change elements in a matrix to a combination of other elements?

Another way using Cases: ...
• 25.2k
Accepted

### Why the replacement rule works okay for scalars but not okay for matrices?

Make use of the NonConstants option to D: ...
• 131k