# Tag Info

### Sort sequences by their "randomness"

Using Entropy: SortBy[mat, Entropy] {{1, 1, 1, 1, 1}, {2, 2, 2, 2, 2}, {1, 2, 3, 4, 5}, {1, 3, 4, 7, 9}, {1, 3, 5, 7, 9}, {5, ...

### Finding equal values in a list

Using the Query "fork-operator" Query[All /* Transpose, {First, Length}] @ Split[v] {{13.51, 12.36, 12.85}, {2, 4, 4}}...

### How can I get the determinant of an 8x8 matrix in a particular form?

Welcome to Mathematica StackExchange. This answer is a bit tedious, but it works. Change the exponentials to trigs: ...
Accepted

### Solve a non-trivial matrix equation for an unknown matrix

Doing a Cholesky decomposition, gives the answer practically instantaneously: ...
1 vote

### Solve a non-trivial matrix equation for an unknown matrix

This is only half the answer. I am able to solve for D, but to get B from D seems another problem. Note, B is symmetric. But then B.Transpose is B.B. And this is also symmetric. We may solve Dmatrix ==...
Accepted

### Commutant of set of matrices

Take a random matrix: n = 3; M = RandomInteger[{-10, 10}, {n, n}] (* {{9, 1, 8}, {-7, 8, -3}, {7, 10, -7}} *) Build a matrix of unknowns: ...
1 vote

### Change last column of a matrix

Using Lookup: ...
1 vote

### Change last column of a matrix

ReplaceAt, introduced with V 13.1, is an ideal candidate for this task: ...

### How can I construct a distance table?

Using GroupBy and Dataset as display function: ...

### How to multiply specific columns in a matrix of data?

Since Version 13.1 there is Threaded: ...

### Remove Successive Duplicate From A Large List (200k by 4 matrix)

m = {{1, 1, 1, 1}, {2, 2, 0, 2}, {0, 1, 0, 0}, {2, 2, 0, 0}}; Since V 13.1 we have DeleteAdjacentDuplicates /@ m {{1}, {2, 0, ...
1 vote
Accepted

### Gauss elimination with pivoting error

If I make the following smallest possible change to your code: ...

### Function to replace values of elements of matrix with 0 unless the value is -1

SparseArray[Position[amat,-1]-> -1, Dimensions@amat]//Normal (* { {0,0,-1,0,0,0,0}, {0,0,-1,0,0,0,0}, {0,-1,0,0,0,0,0}, {0,0,0,0,0,-1,0} } *) ...

### Function to replace values of elements of matrix with 0 unless the value is -1

One approach I always fall back on is to create a function that does the basic task: g[x_] := Piecewise[{{-1, x == -1}, {0, x =!= -1}}]; Then the function can be ...

### Function to replace values of elements of matrix with 0 unless the value is -1

Using ReplacePart with Position: ...

### Removing duplicates between sublists

f = x |-> Select[First@x, FreeQ[Flatten@Rest@x, #] &]; f[RotateLeft[list, #]] & /@ Range[0, Length@list - 1] (*{{6, 6, 4}, {}, {3, 2, 3}, {-1}}*)

### Removing duplicates between sublists

First, you can use Subsets, Intersection and DeleteDuplicates to find all excluded numbers, ...
Accepted

### Modeling Infection Spread among Different Age Groups with Contact Matrix

I really enjoy your epidemic series :-) It is always better to decouple the weedy details of a specific model from the key question. Key question should be purified to bare minimum. Perhaps helpful, --...

### Removing duplicates between sublists

MapApply[DeleteElements[#1,Flatten[{##2}]]&]@NestList[RotateLeft, #,Length@#-1]&@list (* {{6,6,4},{},{3,2,3},{-1}} or ...
1 vote

### How to reduce the dimension of a matrix by matrix operation?

Following @Sjoerd Smit's comments, I have the following answer to my question: ...

...

### Removing duplicates between sublists

uniqueToParentList = MapIndexed[DeleteCases[Alternatives @@ Flatten @ Drop[list, #2]] @ # &]; uniqueToParentList @ list ...

### Removing duplicates between sublists

Probably much more mathematica-like ways to do this. I think using MemberQ as a test could be slow but I am not sure on this. ...
Accepted

### Removing duplicates between sublists

Something along these lines maybe? MapThread[Cases[#1, Alternatives @@ #2] &, {list, UniqueElements[list]}] Or ...

### Function to replace values of elements of matrix with 0 unless the value is -1

We can squish the upper and lower bounds of Clip together at -1 to get the desired output: ...

### Function to replace values of elements of matrix with 0 unless the value is -1

Using Syed's input example: SeedRandom; amat = RandomInteger[{-3, 3}, {4, 7}]; 1. You can use Unitize as follows: ...
Accepted

### Function to replace values of elements of matrix with 0 unless the value is -1

Using the data of @Syed: ReplaceAt[x_ /; x != -1 :> 0, {All, All}] @ amat {{0, 0, -1, 0, 0, 0, 0}, {0, 0, -1, 0, 0, 0, 0}, {0, -1, 0, 0, 0, 0, 0}, {0, 0, 0, 0, ...

### Function to replace values of elements of matrix with 0 unless the value is -1

As an example: SeedRandom; (amat = RandomInteger[{-3, 3}, {4, 7}]) // MatrixForm MatrixForm /@ {amat, amat /. {a_ /; a != -1 -> 0}}
1 vote

### How to change the first value and last value in a matrix?

Using ReplaceAll: ...
1 vote

### Nonzero element positions of a matrix

Using Position, Condition and Table: ...

### Nonzero element positions of a matrix

Using SequencePosition: First /@ SequencePosition[#, {Except}] & /@ m {{1, 2}, {1, 3}}

### How to change the first value and last value in a matrix?

Using SubsetMap: (introduced April 16, 2019) ...

### Nonzero element positions of a matrix

m = {{1, 2, 0}, {4, 0, 9}}; Flatten @* Values @* KeyDrop @* PositionIndex /@ m {1, 2}, {1, 3}}

### How to change the first value and last value in a matrix?

mat = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}}; Since V 12.2 there is ApplyTo (//=): Borrowing ...

### Building matrix from relational data

We can also use Merge: ...

### Replace element in array by checking condition in another list

First, you can use GroupBy to construct a rule: ...
1 vote

### Replace element in array by checking condition in another list

Using Lookup: ...
1 vote

...
1 vote

### How to delete duplicates of certain values in list of lists in a specific column of all sublists?

Since Version 10.1 we can define: ...

...
Accepted

### Analyzing football games (pairing matrix)

You can use GroupBy, Query (with the "add a column" syntax, and ReverseSortBy. ...

### Analyzing football games (pairing matrix)

Assuming data is stored in a variable called data: ...

### Analyzing football games (pairing matrix)

One way to do it: aggResults = GroupBy[data, First -> Last, Total] <|{"Arsenal", "Brighton"} -> 14, {"Arsenal", "...

### Analyzing football games (pairing matrix)

Starting from your "data", we scan every element and use "Sow" to put the points in a list. "Sow" works like "first com, first served". Therefore, to get the ...
Accepted

### Plot several graphs of a function density distribution using Table

DensityPlot has the Attibute "HoldAll": Attributes[DensityPlot] {HoldAll, Protected, ReadProtected} Therefore, if you want to evaluate "ps[B]" ...
1 vote

### How do I get a coefficient matrix from a second order ODE's system?

Looking what you have done aboove in your ask, I did it (turn a 2nd order ODE system in 4 equations 1st order ODE system). But, as I said, I need to comper this 2 situations (2nd order ODE system, ...

### How do I get a coefficient matrix from a second order ODE's system?

\begin{align*} x^{\prime\prime} & =\frac{k_{2}}{m_{1}}y-\frac{k_{1}+k_{2}}{m_{1}}x\\ y^{\prime\prime} & =\frac{k_{2}}{m_{2}}x-\frac{k_{3}+k_{2}}{m_{2}}y \end{align*} Let \$x_{1}=x,x_{2}=x^{\...
1 vote

### How do I get a coefficient matrix from a second order ODE's system?

Using CoefficientArrays: ...