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]=
Introduced in 1988
(1.0)
| Updated in 2003
(5.0)