ArrayDepth

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)

Find the depth to which an array is full:

Scope  (4)

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

ArrayDepth works with special array types, including SparseArray objects:

SymmetrizedArray objects:

NumericArray objects:

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

ArrayDepth works with any head, not just List:

Options  (4)

AllowedHeads  (4)

Only consider nested expressions with head List:

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

Allow lists and numeric arrays at different levels:

Different heads cannot be mixed at the same level:

Allow a mixture of both heads at the same level:

Allow List as well as other general array representations:

Only allow the head List:

Both settings disallow general heads:

Allow any head at each level of the array:

An array has a consistent head at each level:

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

Properties & Relations  (8)

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

ArrayDepth always returns a non-negative integer:

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

It also allows any single head at successive levels:

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

However, it excludes arbitrary heads:

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

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

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

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

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

Depth considers the deepest part of an expression:

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

Possible Issues  (1)

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

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

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

CMS

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

BibTeX

@misc{reference.wolfram_2024_arraydepth, author="Wolfram Research", title="{ArrayDepth}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/ArrayDepth.html}", note=[Accessed: 08-December-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_arraydepth, organization={Wolfram Research}, title={ArrayDepth}, year={2020}, url={https://reference.wolfram.com/language/ref/ArrayDepth.html}, note=[Accessed: 08-December-2024 ]}