ArrayQ
Details
- In a full array, all parts at a particular level must be lists of the same length, though different parts may use different list representations.
- A full array is also known as a rectangular array.
- Possible representations of an array include: »
-
{…} or List[…], {{…},{…},…}, etc. an ordinary list, possibly nested SparseArray[…] a sparse array TabularColumn[…], PermutationMatrix[…], QuantityArray[…], SymmetrizedArray[…], etc. a structured array {a1,a2,…}, where ArrayQ[ai] is True a list of ordinary, sparse, and/or structured arrays » - ArrayQ[expr,1|2] tests whether expr is either a vector or a matrix. »
- The empty list {} is a zero-length vector. »
- Common values of test in ArrayQ[expr,patt,test] for use with numeric arrays include:
-
NumberQ test if expr is an array of explicit numbers NumericQ test if expr is an array of numeric expressions Positive test if expr is an array of positive numbers RealValuedNumberQ test if expr is an array of numbers with head Integer, Rational or Real RealValuedNumericQ test if expr is an array of numeric expressions with real values - Structural tests commonly used include:
-
IntegerQ test if expr is an array of integers PolynomialQ[#,x]& test if expr is an array of polynomials in x QuantityQ test if expr is an array of quantities StringQ test if expr is an array of strings
Examples
open all close allBasic Examples (2)
A vector of numbers is a full array:
ArrayQ[{1, 2, 3, 4}]A vector in which one element is itself a list is not a full array:
ArrayQ[{1, 2, {3}, 4}]A ragged collection of nested lists is not a full array:
ArrayQ[{{1, 2}, {3}}]ArrayQ[{{1, 2}, {3, 4}}]Scope (11)
Many different heads can represent an array:
ArrayQ[SparseArray[{{1, 3} -> a, {5, 1} -> b}]]ArrayQ[TabularColumn[{1, 2, 3}, "Integer8"]]ArrayQ[SymmetrizedArray[{1, 2, 3} -> 1, {3, 3, 3}, Antisymmetric[All]]]ArrayQ[{1, 2, 3, 4}, 1]ArrayQ[{{1, 2}, {3, 4}}, 1]ArrayQ[{1, 2, 3, 4}, 2]ArrayQ[{{1, 2}, {3, 4}}, 2]Test for a vector or a matrix:
ArrayQ[{1, 2, 3, 4}, 1 | 2]ArrayQ[{{1, 2}, {3, 4}}, 1 | 2]An array can have elements in different representations of a list:
mat = {{1, 2, 3}, SparseArray[Automatic, {3}, 0, {1, {{0, 1}, {{3}}}, {a}}], TabularColumn[{4, 5, 6}, "Integer64"]};
ArrayQ[mat]ArrayQ[mat, 2]For deeper arrays, more combinations are possible:
arr = {mat, SymmetrizedArray[{{1, 2} -> b, {3, 3} -> d}, {3, 3}, Symmetric[{1, 2}]]}ArrayQ[arr, 3]View the contents of the array:
arr//MatrixFormArrayQ[{1, 2, 3, x}, 1, NumericQ]Test for an array of any depth with numeric entries:
ArrayQ[{{{E, 1}, {Pi, 2}}, {{Sin[1], Cos[2]}, {Sinh[1], Cosh[1]}}}, _, NumericQ]Test instead for entries that are explicit numbers:
ArrayQ[{{{E, 1}, {Pi, 2}}, {{Sin[1], Cos[2]}, {Sinh[1], Cosh[1]}}}, _, NumberQ]Test for a vector of real-valued numeric quantities:
ArrayQ[{1, Pi, Sin[1], Sqrt[2]}, 1, RealValuedNumericQ]Faster test for explicit real-valued numbers:
ArrayQ[{1, Pi, Sin[1], 3 / 4}, 1, RealValuedNumberQ]Test for an array of odd depth containing numbers that are integers when rounded to two decimal places:
ArrayQ[{1, 1.005, 1.997}, _ ? OddQ, Abs[# - Round[#]] < 0.005&]ArrayQ[{{"a", "b"}, {"c", "d"}}, 2, StringQ]ArrayQ[{{"a", "b"}, {c, d}}, 2, StringQ]Test for a vector or matrix of polynomials in x:
ArrayQ[{1, x, 1 + x, x ^ 2 + 2x + 1}, 1 | 2, PolynomialQ[#, x]&]ArrayQ[{1, x, Sin[x], Exp[x]}, 1 | 2, PolynomialQ[#, x]&]Applications (1)
Define a function that only evaluates with arrays:
iptp[a_ ? ArrayQ, x_] := Module[{n, at = a},
n = ArrayDepth[a];
Do[
at = Transpose[at, RotateRight[Range[ArrayDepth[at]]]];
at = Map[InterpolatingPolynomial[#, Subscript[x, i]]&, at, {n - i}],
{i, n}];
at]This constructs the tensor product interpolating polynomial assuming integer coordinates:
data = {{{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}}, {{13, 14, 15, 16}, {17, 18, 19, 20}, {21, 22, 23, 24}}};
poly = iptp[data, x]The polynomial interpolates the data:
pos = Position[data, _ ? NumberQ];
poly /. Map[Thread[{Subscript[x, 1], Subscript[x, 2], Subscript[x, 3]} -> #]&, pos]% === Extract[data, pos]Properties & Relations (5)
An empty list is considered a zero-length vector:
ArrayQ[{}, 1]VectorQ[expr] is equivalent to ArrayQ[expr,1]:
v = {1, 2., E, Pi + I};{VectorQ[v], ArrayQ[v, 1]}VectorQ[expr,test] is equivalent to ArrayQ[expr,1,test]:
{VectorQ[v, NumericQ], ArrayQ[v, 1, NumericQ]}{VectorQ[v, Im[#] == 0&], ArrayQ[v, 1, Im[#] == 0&]}MatrixQ[expr] is equivalent to ArrayQ[expr,2]:
m = RandomReal[1, {2, 2}]{ArrayQ[m, 2], MatrixQ[m]}MatrixQ[expr] is equivalent to ArrayQ[expr,2]:
{ArrayQ[m, 2, MachineNumberQ], MatrixQ[m, MachineNumberQ]}{ArrayQ[m, 2, IntegerQ], MatrixQ[m, IntegerQ]}For a depth-3 array arr, VectorQ[arr,MatrixQ] and MatrixQ[arr,VectorQ] give True:
arr = Array[a, {2, 3, 4}];
{ArrayQ[arr, 3], VectorQ[arr, MatrixQ], MatrixQ[arr, VectorQ]}The converse of this statement is False:
narr = {Array[a, {3, 4}], Array[a, {3, 5}]};
{ArrayQ[narr, 4], VectorQ[narr, MatrixQ], MatrixQ[narr, VectorQ]}ArrayQ effectively uses AllowedHeads"ListLike":
mat = {SparseArray[{1, 2}], QuantityArray[{1, 2}, "Meters"]};
expr = f[f[1, 2], f[3, 4]];{ArrayQ[mat], ArrayQ[expr]}{ArrayDepth[mat, AllowedHeads -> "ListLike"], ArrayDepth[expr, AllowedHeads -> "ListLike"]}{Dimensions[mat, AllowedHeads -> "ListLike"], Dimensions[expr, AllowedHeads -> "ListLike"]}See Also
ArrayDepth MatrixQ VectorQ Dimensions PadLeft ArrayFlatten Array
Function Repository: TableQ
Tech Notes
Related Guides
History
Introduced in 2003 (5.0) | Updated in 2012 (9.0)
Text
Wolfram Research (2003), ArrayQ, Wolfram Language function, https://reference.wolfram.com/language/ref/ArrayQ.html (updated 2012).
CMS
Wolfram Language. 2003. "ArrayQ." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2012. https://reference.wolfram.com/language/ref/ArrayQ.html.
APA
Wolfram Language. (2003). ArrayQ. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ArrayQ.html
BibTeX
@misc{reference.wolfram_2026_arrayq, author="Wolfram Research", title="{ArrayQ}", year="2012", howpublished="\url{https://reference.wolfram.com/language/ref/ArrayQ.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_arrayq, organization={Wolfram Research}, title={ArrayQ}, year={2012}, url={https://reference.wolfram.com/language/ref/ArrayQ.html}, note=[Accessed: 13-June-2026]}