WolframLang: Nested List, Array, Tree, Dimensions

By Xah Lee. Date: . Last updated: .

List is critically important in WolframLang. Here's some notion on tree, array, you need to understand.

Matrix (aka rectangular array, n-dimensional array)

A nested list where there are same number of elements at each level of nesting. e.g. {{3,1}, {4, 5}, {2, 4}}.

Tree

(aka jagged array) A arbitrarily nested list. e.g. {3, {4, 5}, {9}}.

Dimensions[expr]

Shape of rectangular array. A list of integers that is the count at each level of nesting.

Example: Dimensions on a 3 by 2 matrix {{3,1}, {4, 5}, {2, 4}} return {3,2}.

Dimensions

Dimensions[{a, b}] ===
{2}

Dimensions[{x, y, z}] ===
{3}

Dimensions[{{a, b}, {c, d}}] ===
{2, 2}

Dimensions[{{{a}, {b}}, {{c}, {d}}}] ===
{2, 2, 1}

(* jagged array. return the max regularity *)
Dimensions[{{{a}, {b}}, {{c}, d}}] ===
{2, 2}
ArrayDepth[expr]

same as Length[Dimensions[expr]]

ArrayDepth

WolframLang List