WOLFRAM

ArrayDepth[expr]

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

Examples

open allclose all

Basic Examples  (1)Summary of the most common use cases

Find the depth to which an array is full:

Out[1]=1

Scope  (4)Survey of the scope of standard use cases

ArrayDepth counts only dimensions at which an expression is not "ragged":

Out[8]=8

ArrayDepth works with special array types, including SparseArray objects:

Out[1]=1
Out[2]=2

SymmetrizedArray objects:

Out[3]=3
Out[4]=4

NumericArray objects:

Out[5]=5
Out[6]=6

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

Out[1]=1

ArrayDepth works with any head, not just List:

Out[1]=1

Options  (4)Common values & functionality for each option

AllowedHeads  (4)

Only consider nested expressions with head List:

Out[1]=1

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

Out[2]=2

Allow lists and numeric arrays at different levels:

Out[1]=1

Different heads cannot be mixed at the same level:

Out[2]=2

Allow a mixture of both heads at the same level:

Out[3]=3

Allow List as well as other general array representations:

Out[1]=1

Only allow the head List:

Out[2]=2

Both settings disallow general heads:

Out[3]=3
Out[4]=4

Allow any head at each level of the array:

Out[1]=1

An array has a consistent head at each level:

Out[2]=2

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

Out[3]=3

Properties & Relations  (8)Properties of the function, and connections to other functions

Length[Dimensions[expr]] equals ArrayDepth[expr]:

Out[1]=1

ArrayDepth always returns a non-negative integer:

Out[1]=1
Out[2]=2
Out[3]=3

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

Out[1]=1

It also allows any single head at successive levels:

Out[2]=2

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

Out[3]=3

However, it excludes arbitrary heads:

Out[4]=4

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

Out[3]=3
Out[4]=4
Out[5]=5

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

Out[2]=2

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

Out[3]=3

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

Out[1]=1

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

Out[1]=1

Depth considers the deepest part of an expression:

Out[2]=2

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

Out[1]=1
Out[2]=2

Possible Issues  (1)Common pitfalls and unexpected behavior

Numeric expressions report array depth based of the structure of their FullForm:

Out[2]=2

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

Out[3]=3
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).

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 ]}

@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 ]}

@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 ]}