ArrayDepth
gives the depth to which expr is a full array, with all the parts at a particular level having the same length.
Details and Options

- ArrayDepth[list] is equivalent to Length[Dimensions[list]].
- For special array objects like SparseArray, NumericArray and QuantityArray, ArrayDepth yields the depth of the corresponding ordinary lists.
- The following option can be given:
-
AllowedHeads Automatic what heads to allow at each level of the array - Settings for the AllowedHeads option include:
-
Automatic default settings Inherited allow only Head[expr] at any level h allow only head h at any level {h1,…} allow any of h1,… at different levels h1h2… allow the hi at the same or different levels "ListLike" allow List and related heads All allow any head at different levels Full allow any head at any level - The setting AllowedHeads"ListLike" allows all heads recognized by ArrayQ, which include List, SparseArray and structured array heads like QuantityArray and SymmetrizedArray.
- With the default setting AllowedHeads->Automatic, successive levels in expr must have the same head, except that ordinary lists, sparse arrays and structured arrays are considered the same head.
Examples
open allclose allBasic Examples (1)Summary of the most common use cases
Scope (4)Survey of the scope of standard use cases
ArrayDepth counts only dimensions at which an expression is not "ragged":

https://wolfram.com/xid/0cg41kau6-nxp

https://wolfram.com/xid/0cg41kau6-co6

ArrayDepth works with special array types, including SparseArray objects:

https://wolfram.com/xid/0cg41kau6-s21


https://wolfram.com/xid/0cg41kau6-gy1

SymmetrizedArray objects:

https://wolfram.com/xid/0cg41kau6-k8hdtp


https://wolfram.com/xid/0cg41kau6-dd5rgd

NumericArray objects:

https://wolfram.com/xid/0cg41kau6-o1re6


https://wolfram.com/xid/0cg41kau6-uwc35r

Find the depth of a matrix that is a mixture of List and different special array heads:

https://wolfram.com/xid/0cg41kau6-k3u74c

ArrayDepth works with any head, not just List:

https://wolfram.com/xid/0cg41kau6-vxk

Options (4)Common values & functionality for each option
AllowedHeads (4)
Only consider nested expressions with head List:

https://wolfram.com/xid/0cg41kau6-k9dyn2

By default, rectangular nested expressions with any head are considered arrays:

https://wolfram.com/xid/0cg41kau6-khkuch

Allow lists and numeric arrays at different levels:

https://wolfram.com/xid/0cg41kau6-7clrof

Different heads cannot be mixed at the same level:

https://wolfram.com/xid/0cg41kau6-3nvfbn

Allow a mixture of both heads at the same level:

https://wolfram.com/xid/0cg41kau6-548h4q

Allow List as well as other general array representations:

https://wolfram.com/xid/0cg41kau6-9ml35q

Only allow the head List:

https://wolfram.com/xid/0cg41kau6-70jjg6

Both settings disallow general heads:

https://wolfram.com/xid/0cg41kau6-vcu7w6


https://wolfram.com/xid/0cg41kau6-scvobz

Allow any head at each level of the array:

https://wolfram.com/xid/0cg41kau6-fwqt97

An array has a consistent head at each level:

https://wolfram.com/xid/0cg41kau6-xyv2j1

Completely ignore heads, looking only at the tree structure of the expression:

https://wolfram.com/xid/0cg41kau6-lleebw

Properties & Relations (8)Properties of the function, and connections to other functions
Length[Dimensions[expr]] equals ArrayDepth[expr]:

https://wolfram.com/xid/0cg41kau6-t2q1lr

ArrayDepth always returns a non-negative integer:

https://wolfram.com/xid/0cg41kau6-plvazy


https://wolfram.com/xid/0cg41kau6-szy46a


https://wolfram.com/xid/0cg41kau6-5o5zhi

The default value of the option AllowedHeads allows mixtures of list, sparse and structured arrays:

https://wolfram.com/xid/0cg41kau6-7j5w0a

It also allows any single head at successive levels:

https://wolfram.com/xid/0cg41kau6-hrep0

The following setting of AllowedHeads imitates the default behavior with respect to list-like arrays:

https://wolfram.com/xid/0cg41kau6-bqcoq5

However, it excludes arbitrary heads:

https://wolfram.com/xid/0cg41kau6-wtahnf

VectorQ, MatrixQ and ArrayQ effectively use AllowedHeads"ListLike":

https://wolfram.com/xid/0cg41kau6-pmpfyl

https://wolfram.com/xid/0cg41kau6-4b78jt

https://wolfram.com/xid/0cg41kau6-iksb32


https://wolfram.com/xid/0cg41kau6-165ab7


https://wolfram.com/xid/0cg41kau6-sm8t33

The setting AllowedHeads"ListLike" does not include ByteArray and NumericArray:

https://wolfram.com/xid/0cg41kau6-b4elld

https://wolfram.com/xid/0cg41kau6-ieinh6

Combine "ListLike" with the additional heads to allow the combination:

https://wolfram.com/xid/0cg41kau6-no0ujw

ArrayDepth[Array[h,dims]] gives Length[dims]:

https://wolfram.com/xid/0cg41kau6-q2t

ArrayDepth only considers the levels to which the expression is completely rectangular:

https://wolfram.com/xid/0cg41kau6-1owf7w

Depth considers the deepest part of an expression:

https://wolfram.com/xid/0cg41kau6-kcrjnc

For completely rectangular expressions, ArrayDepth gives a result one smaller than Depth:

https://wolfram.com/xid/0cg41kau6-4lpecw


https://wolfram.com/xid/0cg41kau6-cyhoza

Possible Issues (1)Common pitfalls and unexpected behavior
Numeric expressions report array depth based of the structure of their FullForm:

https://wolfram.com/xid/0cg41kau6-0s5y0i


https://wolfram.com/xid/0cg41kau6-ymwq71

To treat all numeric expressions as scalars, use the setting List or "ListLike" for AllowedHeads:

https://wolfram.com/xid/0cg41kau6-cjt00d

Wolfram Research (2003), ArrayDepth, Wolfram Language function, https://reference.wolfram.com/language/ref/ArrayDepth.html (updated 2020).
Text
Wolfram Research (2003), ArrayDepth, Wolfram Language function, https://reference.wolfram.com/language/ref/ArrayDepth.html (updated 2020).
Wolfram Research (2003), ArrayDepth, Wolfram Language function, https://reference.wolfram.com/language/ref/ArrayDepth.html (updated 2020).
CMS
Wolfram Language. 2003. "ArrayDepth." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020. https://reference.wolfram.com/language/ref/ArrayDepth.html.
Wolfram Language. 2003. "ArrayDepth." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020. https://reference.wolfram.com/language/ref/ArrayDepth.html.
APA
Wolfram Language. (2003). ArrayDepth. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ArrayDepth.html
Wolfram Language. (2003). ArrayDepth. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ArrayDepth.html
BibTeX
@misc{reference.wolfram_2025_arraydepth, author="Wolfram Research", title="{ArrayDepth}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/ArrayDepth.html}", note=[Accessed: 01-June-2025
]}
BibLaTeX
@online{reference.wolfram_2025_arraydepth, organization={Wolfram Research}, title={ArrayDepth}, year={2020}, url={https://reference.wolfram.com/language/ref/ArrayDepth.html}, note=[Accessed: 01-June-2025
]}