If list1d
is a simple 1-d list, then list1d[[{i, j, k}]]
evaluates to a list consisting of the i
-th, j
-th, and k
-th element of list1d
.
Is there an analogous construction for extracting a list of elements from nested lists?
More formally, if list1d = Take[Alphabet[], 10]
(for example), then the following three expressions produce the same result, the list of elements {"c", "g", "d"}
:
Part[list1d, Sequence @@ #] & /@ {{3}, {7}, {4}} (* 1.1 *)
Part[list1d, {3, 7, 4}] (* 1.2 *)
list1d[[{3, 7, 4}]] (* 1.3 *)
But now suppose that list2d = Partition[Alphabet[], UpTo[10]]
. That is, array2d
is a list of lists (with lengths 10, 10, and 6).
Then an expression analogous to 1.1 above
Part[list2d, Sequence @@ #] & /@ {{3, 3}, {1, 7}, {2, 4}} (* 2.1 *)
...also evaluates to a list of elements (this time {"w", "g", "n"}
).
Are there expressions analogous to 1.2 and 1.3 (and equivalent to 2.1) for the 2d case1?
1 Here, by "analogous to 1.2 and 1.3", I mean that they are simple expressions with head _Part
, and evaluating to a list of elements of list2d
.
Extract[array2d,{{3, 3}, {1, 7}, {2, 4}} ]
$\endgroup$