This is documentation for Mathematica 4, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)
Wolfram Research, Inc.

Ordering in ListsAdvanced Topic: Combinatorial Operations

1.8.14 Advanced Topic: Rearranging Nested Lists

You will encounter nested lists if you use matrices or generate multidimensional arrays and tables. Rearranging nested lists can be a complicated affair, and you will often have to experiment to get the right combination of commands.

Functions for rearranging nested lists.

Here is a array.

In[1]:= t = {{a, b}, {c, d}, {e, f}}


You can rearrange it to get a array.

In[2]:= Transpose[t]


This "flattens out" sublists. You can think of it as effectively just removing the inner sets of braces.

In[3]:= Flatten[t]


Here is a array.

In[4]:= t = Table[i^2 +j^2 +k^2, {i, 2}, {j, 2}, {k, 2}]


This flattens out all the levels.

In[5]:= Flatten[t]


This flattens only the first level of sublists.

In[6]:= Flatten[t, 1]


This flattens out only the sublist that appears at position 2.

In[7]:= FlattenAt[{{a, b}, {c, d}}, 2]


There are many other operations you can perform on nested lists. We will discuss some more of them when we look at Map, Apply, Scan and Level in Part 2.

Ordering in ListsAdvanced Topic: Combinatorial Operations