Flatten

Flatten[list]
flattens out nested lists.

Flatten[list, n]
flattens to level n.

Flatten[list, n, h]
flattens subexpressions with head h.

Flatten[list, {{s11, s12, ...}, {s21, s22, ...}, ...}]
flattens list by combining all levels to make each level i in the result.

DetailsDetails

  • Flatten "unravels" lists, effectively just deleting inner braces.
  • Flatten[list, n] effectively flattens the top level in list n times.
  • Flatten[f[e, ...]] flattens out subexpressions with head f.
  • If the are matrices, Flatten[{{m11, m12}, {m21, m22}}, {{1, 3}, {2, 4}}] effectively constructs a single matrix from the "blocks" .
  • Flatten[list, {{i1}, {i2}, ...}] effectively transposes levels in list, putting level in list at level k in the result. Note that the function Transpose in effect uses an inverse of this specification.
  • Flatten flattens out levels in SparseArray objects just as in the corresponding ordinary arrays. »
New in 1 | Last modified in 6
New to Mathematica? Find your learning path »
Have a question? Ask support »