MatrixQ

MatrixQ[expr]
gives True if expr is a list of lists or a two-dimensional SparseArray object that can represent a matrix, and gives False otherwise.

MatrixQ[expr, test]
gives True only if test yields True when applied to each of the matrix elements in expr.

DetailsDetails

  • MatrixQ[expr] gives True only if expr is a list and each of its elements is a list of the same length, containing no elements that are themselves lists, or if expr is a two-dimensional SparseArray object.
  • MatrixQ[expr, NumberQ] tests whether expr is a numerical matrix.

ExamplesExamplesopen allclose all

Basic Examples (3)Basic Examples (3)

Test of whether an object is a matrix:

In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=

These are not matrices:

In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=

Use tests to generalize and specialize:

In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=
New in 1 | Last modified in 5
New to Mathematica? Find your learning path »
Have a question? Ask support »