Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options not deleted user 85558

Questions on the manipulation of matrices in Mathematica.

1 vote
Accepted

making elements of matrix into integers

We define your matrix: matrix = {{-1., -1., -1., -1., -1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.}, {1., 0., 0., 0., 0., -1., -1., -1., -1., 0., 0., 0., 0., 0., 0., 0., 0. … }, {0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 1., 1., 0., -1.}, {0., 0., 0., 0., 1., 0., 0., 0., 1., 0., 0., 0., 0., 0., 1., 0., 0., 0., 1., 1.}}; and then we perform matrix
bmf's user avatar
  • 17k
5 votes

How to fill lower trianglar matrix with elements of a vector

Though there are already excellent answers by Michael and cvgmt, we still have a long way to go to ten ways of achieving the result. Borrowing from Mr.Wizard's answer here MatrixForm@PadRight@partitio …
bmf's user avatar
  • 17k
3 votes
Accepted

How to construct a custom-made matrix conditional on a set of rules?

So, the question essentially boils down to the following two tasks: How do I delete all negative elements of a matrix? How do I delete all positive elements of a matrix? … How do I delete all negative elements of a matrix? You have the following options bobhanlon = Clip[m0, {0, Infinity}]; jdp = (m0 /. _?(# < 0 &) :> 0); bmf01 = m0 /. _? …
bmf's user avatar
  • 17k
2 votes

How to repeat a matrix on it's side?

Since @kglr already used KroneckerProduct, I am demonstrating a solution that uses TensorProduct + **ArrayFlatten** 🎊 = ArrayFlatten@TensorProduct[{ConstantArray[1, #2]}, #] &; and then 🎊[mat, 3] …
bmf's user avatar
  • 17k
2 votes

Remove columns basing on binary sequence

Explanation: Rename all elements equal to 0 in the original list to something, say x Multiply each sublist by the mask Keep only the elements that are not equal to 0 Rename x to 0 which are the ones f …
bmf's user avatar
  • 17k
3 votes

Prepend 0 to sublists

It's a bit strange for me that no answer used Riffle With list = RandomInteger[{1, 9}, {4, 5}]; zero = 0~ConstantArray~{Length@list}; we do: ArrayReshape[ Riffle[zero, list], {(Dimensions@list)[[ …
bmf's user avatar
  • 17k
2 votes

Identify the positions of a marker in sublists

Since @kglr suggested, already, the use of SparseArray here's another way to go about it Flatten /@ GatherBy[SparseArray[#]["NonzeroPositions"] & /@ ZeroCrossings, First] {{3, 9}, {4, 5, 8, 12, …
bmf's user avatar
  • 17k
2 votes

Proving (or refuting) TU (totally unimodularity) of a matrix nxm

, 0}}; Dimensions@matrix MatrixForm@matrix {7, 7} For the reader's convenience, the task at hand is to compute the determinant of the initial/seed matrix and all submatrices. … For the seed $7 \times 7$ matrix we run obo = Minors[matrix, 1, Identity]; tbt = Minors[matrix, 2, Identity]; ttbtt = Minors[matrix, 3, Identity]; fbf = Minors[matrix, 4, Identity]; ffbff = Minors[matrix
bmf's user avatar
  • 17k
4 votes

Jacobian matrix evaluation at a point

VectorQ, x_List] := Det[JacobianMatrix[f, x]] /; Equal @@ (Dimensions /@ {f, x}) The Jacobian matrix is JacobianMatrix[{f1[x, y], f2[x, y]}, {x, y}] and you can evaluate at a point using either …
bmf's user avatar
  • 17k
6 votes

How do I flatten a matrix of lists while maintaining the structure of the list?

We grab the matrix from the OP matrix = {{{a, b, c}, {e, f, g}}, {{h, i, j}, {k, l, m}}} 0. … Using Sum The code is Sum[matrix[[xx1, xx2]], {xx1, 1, (Dimensions@matrix)[[1]]}, {xx2, 1, (Dimensions@matrix)[[2]]}] The above is an automated approach of the following matrix[[1, 1]] + matrix[[1, …
bmf's user avatar
  • 17k
3 votes

Determine value of parameters in a matrix such that it is unitary

Expanding my comment: U = {{x1, -x2, x3}, {-x1, 0, x3}, {x1, x2, 0}}; U // MatrixForm The other required matrices Inverse[U] // MatrixForm Transpose[U] // MatrixForm I am hoping that now it …
bmf's user avatar
  • 17k
3 votes

Create Matrix where its entries come from functions

Another possibility n = 5; first = Table[i^2, {i, n}]; rest = Table[2 i j, {i, n}, {j, 2, n}]; MatrixForm@ArrayReshape[Thread@{first, rest}, {n, n}]
bmf's user avatar
  • 17k
7 votes

How to use ArrayFlatten

@Nasser gave the canonical answer and this is more of a general comment, hopefully useful. Instead of using ArrayFlatten you can consider ArrayReshape That is x = ConstantArray[0, 4]; x = Thread@{x}; …
bmf's user avatar
  • 17k
1 vote

Getting zero for special positions in a matrix

I think that's the simplest way list = {{1, 2, 3, 2, 3}, {3, 1, 1, 2, 3}, {3, 2, 1, 3, 2}, {1, 2, 1, 1, 1}}; list /. {a_, b_, c_, d_, e_} :> {a, 0, 0, d, 0}
bmf's user avatar
  • 17k
3 votes

Delete zero rows in a matrix

I am adding some contributions. As far as I checked there's no overlap with the suggestions so far. If someone spots something, I would appreciate a comment and I will remove the duplicate. I am grabb …
bmf's user avatar
  • 17k

15 30 50 per page