Search Results
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 |
Questions on the manipulation of matrices in Mathematica.
3
votes
Building a matrix in block matrix format
m30 = ConstantArray[3, {30, 30}];
i30 = IdentityMatrix[30];
m48 = ConstantArray[4, {48, 48}];
m12 = ConstantArray[0, {48, 12}];
Transpose@Join[m30, i30]~Join~Join[m12, m48, 2]
4
votes
Position of n largest elements in each row in a matrix that satisfies certain criterion
We can also use the new PositionLargest (since 13.2)
m = {{1, 2, 3}, {3, -2, 1/3}};
Get positions:
p = Flatten @ PositionLargest[#, Min[2, Count[#, u_ /; u > 0.5]]] & /@ m
{{3, 2}, {1}}
Index them:
…
3
votes
How to sum matrix elements based on finding the first (and second) non-zero elements of each...
Using 1066's data
mat = {{0., 0., 0., 0., 0}, {0., 0., 0., 0., 0},
{0., 0., 0., 25.5317, 29.1235}, {0., 0., 0., 0., 8.85471}, {0., 0.,
0., 0., 0}, {0., 0., 0., 0., 0}, {0., 0., 0., 0., 6.90018}, …
2
votes
Split matrix by all-zero columns
mat =
{{0, 0, 0, 0, 0, 1},
{1, 0, 0, 1, 0, 1},
{0, 1, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 1},
{1, 1, 0, 1, 0, 0},
{0, 0, 0, 1, 0, 1}};
Using SequenceSplit (new in 11.3)
MatrixForm @* Transp …
2
votes
How to fill lower trianglar matrix with elements of a vector
n = 5;
v = Range[n (n + 1)/2];
Using FoldPairList and TakeDrop
PadRight @ FoldPairList[TakeDrop, v, Range @ n]
{{1, 0, 0, 0, 0},
{2, 3, 0, 0, 0},
{4, 5, 6, 0, 0},
{7, 8, 9, 10, 0},
{11, 12, 13, 14 …
2
votes
Creation of one column matrix
Using ReplaceAt (new in 13.1)
ReplaceAt[Table[{0}, 4], _ :> {-1}, 1]
Using MapAt
MapAt[{-1} &, Table[{0}, 4], 1]
Both produce
{{-1}, {0}, {0}, {0}}
1
vote
Matrix manipulation
In other cases (few deletions) one could also consider Delete:
m = Partition[Range[400], 20];
del = {{7}, {9}, {12}, {13}, {15}, {16}, {18}, {19}};
m // Delete[del] // Transpose // Delete[del] // T …
5
votes
Using Wolfram Alpha-syntax for transpose, etc
Dot is a special case of Inner
list = {{0, 1}, {0, 2}, {0, 3}};
Inner[Times, list, Transpose[list], Plus] // MatrixForm
list = {{1, 1}, {1, 2}, {1, 3}}
Inner[Power, list, Transpose[list], Plu …
4
votes
Accepted
How do I put matrices next to each other?
Like this?
(a = ConstantArray["A", {4, 3}]) // MatrixForm
(b = ConstantArray["B", {4, 4}]) // MatrixForm
Map[Flatten, Transpose[{a, b}]] // MatrixForm
3
votes
Accepted
Simple subtraction of two square matrices giving strange results
Define Test with SetDelayed (:=)
Clear["Global`*"];
Test[s_, cm_]:=
Module[{a, b, c},
a = s Transpose[s];
b = cm + a;
c = Transpose[s] * Inverse[b] * s;
IdentityMatrix[2] - c]
Test[{{0. …
2
votes
Help with sum specific elements of a matrix in mathematica
list = {{1, 2, 3, 3}, {4, 5, 6, 6}, {7, 8, 9, 9}, {1, 5, 9, 7}};
p = {{2, 1}, {4, 3}};
Using MapApply (new in 13.1)
Total @ MapApply[list[[##]]&] @ p
13
2
votes
How to add rows to a matrix to achieve a given order?
c = 4;
r = 3;
mat = Partition[Range[4 c], c];
Join[mat, Array[a &, {r, n}]] // MatrixForm
3
votes
Accepted
Evaluation of m.v is blocked by applying MatrixForm. Why?
Evaluate Head@mm - There's the answer :)
2
votes
Accepted
Make an effective projection of matrix
A /. "" -> Sequence[]
{{1, 2, 3, 4}, {2, 3, 4}, {3, 4}, {4, 5}}
3
votes
Measures of association, Concordant and Discordant
m = {{{1, 1}, {2, 4}}, {{1, 5}, {2, 4}}, {{1, 1}, {1, 1}}};
Times @@@ (Sign /@ Subtract @@@ m) /. (0 | 1) -> "Concordant" /. -1 -> "Discordant"
{"Concordant", "Discordant", "Concordant"}