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.

Details

  • 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.

Examples

open allclose all

Basic Examples  (3)

Test of whether an object is a matrix:

These are not matrices:

Use tests to generalize and specialize:

Scope  (2)

Test if a matrix has positive (real) entries:

Test if a matrix has real numeric entries:

Faster test for real-valued numbers:

Applications  (1)

Define a function that only evaluates for explicit matrices:

This represents the Hermitian part of a matrix symbolically:

This gets the Hermitian part explicitly:

Properties & Relations  (3)

MatrixQ is a special case of ArrayQ:

A matrix is made up of vectors of equal length:

MatrixQ effectively uses AllowedHeads"ListLike":

Wolfram Research (1988), MatrixQ, Wolfram Language function, https://reference.wolfram.com/language/ref/MatrixQ.html (updated 2003).

Text

Wolfram Research (1988), MatrixQ, Wolfram Language function, https://reference.wolfram.com/language/ref/MatrixQ.html (updated 2003).

CMS

Wolfram Language. 1988. "MatrixQ." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2003. https://reference.wolfram.com/language/ref/MatrixQ.html.

APA

Wolfram Language. (1988). MatrixQ. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/MatrixQ.html

BibTeX

@misc{reference.wolfram_2023_matrixq, author="Wolfram Research", title="{MatrixQ}", year="2003", howpublished="\url{https://reference.wolfram.com/language/ref/MatrixQ.html}", note=[Accessed: 19-March-2024 ]}

BibLaTeX

@online{reference.wolfram_2023_matrixq, organization={Wolfram Research}, title={MatrixQ}, year={2003}, url={https://reference.wolfram.com/language/ref/MatrixQ.html}, note=[Accessed: 19-March-2024 ]}