Qurak

Work with nested lists

How-to 16 stappen, op volgorde uitgevoerd in één sessie. Elke stap is tegen de engine uitgevoerd en de uitvoer hieronder is wat hij opleverde.

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

Gebruikte functies

Gerelateerde recepten

Alle recepten · Functiereferentie · Gebruik dit vanuit een MCP-client