Qurak

Work with nested lists

How-to 16 steps, run in order in one session. Every step was executed against the engine and the output below is what it produced.

Step 1
alist = {{a1, a2, a3, a4}, {b1, b2, b3, b4}, {c1, c2, c3, c4}, {d1, d2, d3, d4}}
Output
{{a1, a2, a3, a4}, {b1, b2, b3, b4}, {c1, c2, c3, c4}, {d1, d2, d3, d4}}
Step 2
MatrixForm[alist]
Output
MatrixForm[{{a1, a2, a3, a4}, {b1, b2, b3, b4}, {c1, c2, c3, c4}, {d1, d2, d3, d4}}]
Step 3
alist[[2]]
Output
{b1, b2, b3, b4}
Step 4
alist[[2, 3]]
Output
b3
Step 5
alist[[All, 3]]
Output
{a3, b3, c3, d3}
Step 6
Flatten[alist]
Output
{a1, a2, a3, a4, b1, b2, b3, b4, c1, c2, c3, c4, d1, d2, d3, d4}
Step 7
MatrixForm[Flatten[alist]]
Output
MatrixForm[{a1, a2, a3, a4, b1, b2, b3, b4, c1, c2, c3, c4, d1, d2, d3, d4}]
Step 8
MatrixForm[{Flatten[alist]}]
Output
MatrixForm[{{a1, a2, a3, a4, b1, b2, b3, b4, c1, c2, c3, c4, d1, d2, d3, d4}}]
Step 9
data = Table[i + j, {i, 1, 5}, {j, 1, 4}]
Output
{{2, 3, 4, 5}, {3, 4, 5, 6}, {4, 5, 6, 7}, {5, 6, 7, 8}, {6, 7, 8, 9}}
Step 10
MatrixForm[data]
Output
MatrixForm[{{2, 3, 4, 5}, {3, 4, 5, 6}, {4, 5, 6, 7}, {5, 6, 7, 8}, {6, 7, 8, 9}}]
Step 11
ListLinePlot[data, AxesOrigin -> {0, 0}]
Output
-Graphics-
Step 12
Mean[data]
Output
{4, 5, 6, 7}
Step 13
Mean[Flatten[data]]
Output
11/2
Step 14
dat = Table[i + j + k, {i, 1, 4}, {j, 1, 4}, {k, 1, 4}];
MatrixForm[dat]
Output
MatrixForm[{{{3, 4, 5, 6}, {4, 5, 6, 7}, {5, 6, 7, 8}, {6, 7, 8, 9}}, {{4, 5, 6, 7}, {5, 6, 7, 8}, {6, 7, 8, 9}, {7, 8, 9, 10}}, {{5, 6, 7, 8}, {6, 7, 8, 9}, {7, 8, 9, 10}, {8, 9, 10, 11}}, {{6, 7, 8, 9}, {7, 8, 9, 10}, {8, 9, 10, 11}, {9, 10, 11, 12}}}]
Step 15
MatrixForm[Mean[dat]]
Output
MatrixForm[{{9/2, 11/2, 13/2, 15/2}, {11/2, 13/2, 15/2, 17/2}, {13/2, 15/2, 17/2, 19/2}, {15/2, 17/2, 19/2, 21/2}}]
Step 16
Mean[Flatten[dat]]
Output
15/2

Functions used

Related recipes

All recipes · Function reference · Use this from an MCP client