Skip to content

IsMatrix ​

Tests whether m is a non-empty, non-ragged rank-2 List of Lists, optionally with every entry satisfying test.

✓ checked against that system · ! checked, with disagreements (hover a chip)Wolfram LanguageMatrixQ✓
IsMatrix(m)True if m is a List of Lists, all the same length, none containing a further List
IsMatrix(m, test)as above, and test holds of every entry
Typed signatures
TypePackageApplies
(any, function?) -> booleancombinatoricsalways

Domain: Collections

Details
  • A ragged List of Lists (rows of different lengths), an empty List, or anything of rank other than exactly 2, is False.

Examples

Basic #
live ↗
InIsMatrix([[1,2],[3,4]])\mathrm{IsMatrix}(\bigl\lbrack\bigl\lbrack1, 2\bigr\rbrack, \bigl\lbrack3, 4\bigr\rbrack\bigr\rbrack)OutTrue\mathrm{True}

Symbolic entries are fine: only the rectangular shape matters

live ↗
InIsMatrix([[a,b],[3,4]])\mathrm{IsMatrix}(\bigl\lbrack\bigl\lbrack a, b\bigr\rbrack, \bigl\lbrack3, 4\bigr\rbrack\bigr\rbrack)OutTrue\mathrm{True}

Rows of unequal length do not form a matrix

live ↗
InIsMatrix([[1],[2,3]])\mathrm{IsMatrix}(\bigl\lbrack\bigl\lbrack1\bigr\rbrack, \bigl\lbrack2, 3\bigr\rbrack\bigr\rbrack)OutFalse\mathrm{False}

A rank-3 array is deeper than a matrix

live ↗
InIsMatrix(Array(a,[2,2,2]))\mathrm{IsMatrix}(\mathrm{Array}(a, \bigl\lbrack2, 2, 2\bigr\rbrack))OutFalse\mathrm{False}
Scope #
live ↗
InIsMatrix([1,2,3])\mathrm{IsMatrix}(\bigl\lbrack1, 2, 3\bigr\rbrack)OutFalse\mathrm{False}
live ↗
InIsMatrix([[1,2],[3]])\mathrm{IsMatrix}(\bigl\lbrack\bigl\lbrack1, 2\bigr\rbrack, \bigl\lbrack3\bigr\rbrack\bigr\rbrack)OutFalse\mathrm{False}
live ↗
InIsMatrix([])\mathrm{IsMatrix}(\bigl\lbrack\bigr\rbrack)OutFalse\mathrm{False}
live ↗
InIsMatrix([[2,4],[6,8]],IsEven)\mathrm{IsMatrix}(\bigl\lbrack\bigl\lbrack2, 4\bigr\rbrack, \bigl\lbrack6, 8\bigr\rbrack\bigr\rbrack, \mathrm{IsEven})OutTrue\mathrm{True}
Properties #

Undefined symbols are not known to be matrices

live ↗
In[IsMatrix(mat),IsMatrix(expr)]\bigl\lbrack\mathrm{IsMatrix}(\mathrm{mat}), \mathrm{IsMatrix}(\mathrm{expr})\bigr\rbrackOut[False,False]\bigl\lbrack\mathrm{False}, \mathrm{False}\bigr\rbrack
About
Examples9
Checked againstWolfram Language 9 agree
CrosswalkWolfram Language

See also: IsVector, IsArray