this is a rather rudimentary question, but I was wondering if there are more efficient ways to do the following:
dd = {{{12, 3, 5}, {14, 10, 11}}, {{15, 76, 65}}}
If I have list dd, I want identify alternative ways to pick out elements in each sublist that are in the same positions and make them into a new list. For example, if I took out the first position of every sublist, I'd get the output:
Output={{12, 14}, {15}}
To make new output lists with the first/last element positions are the easiest and can be achieved through:
lis1 = Map[First, dd, {2}]
lis2 = Map[Last, dd, {2}]
However, to get an output where the "middle" position elements are taken and put into a new list ({{3, 10}, {76}}
) I used:
lis3 = Map[Rest, dd, {2}]
lis4 = Map[First, lis3, {2}]
This seems like a rather roundabout way to obtain the desired list. Would there be a more streamlined alternative which I can Map
directly to list dd and avoid having to manipulating the list first (lis3)?
Map[#[[k]]&, dd, {2}]
with your choice ofk
? $\endgroup$Apply[#k &, dd, {-2}]
, e.g.,Apply[#2 &, dd, {-2}]
. $\endgroup$dd[[ All, All, k ]]
what you need or did I miss something? $\endgroup$dd/.{x_,y_,z_}:> y
$\endgroup$