WolframLang: Nested List, Array, Tree, Dimensions

By Xah Lee. Date: .

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

rectangular array, n-dimensional array, matrix
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. e.g. 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

List

WolframLang in Depth

Basics

Comment, Print

String

Arithmetic

List

Expression, Atom, Head

Boolean

Conditional

Variable

Loop

Data Structure

Function

Pattern Matching

Advanced

Shell Tasks

Misc