Wolfram: Nested List, Array, Tree, Dimensions

By Xah Lee. Date: . Last updated: .

Nested List: Array, Matrix, Tree

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 and ArrayDepth

Dimensions[expr]

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

e.g. a 3 by 2 matrix has dimensions {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 Concepts