Wolfram Language & System 10.4 (2016)|Legacy Documentation

This is documentation for an earlier version of the Wolfram Language.
BUILT-IN WOLFRAM LANGUAGE SYMBOL

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

ExamplesExamplesopen allclose all

Basic Examples  (2)Basic Examples  (2)

Flatten out lists at all levels:

 In[1]:=
 Out[1]=

Flatten only at level 1:

 In[1]:=
 Out[1]=