New answers tagged

2

There are many answers, but I want to give another one that could be not so elegant, but is very suitable for easy modification. It's quite often that you have a list of "objects", where object can be a weirdly nested list, and you need to extract some subset of components possible in different order. l = {{{x1, y1}, z1}, {{x2, y2}, z2}}; {#[[1, 1]], #[[1, ...


4

♭ = ## & @@@ {##} & @@@ # &; ♭ @ {{{x1, y1}, z1}, {{x2, y2}, z2}} {{x1, y1, z1}, {x2, y2, z2}}


2

Example Code Partition[Flatten @ data , 3] Output {{x1, y1, z1}, {x2, y2, z2}} Note: data is your original list Reference Flatten Partition


5

Let's have an answer. data = {{{x1, y1}, z1}, {{x2, y2}, z2}, {{x3, y3}, z3}, {{x4, y4}, z4}}; J.M. Flatten /@ data Append @@@ data m_goldberg ArrayReshape[data, {Length[data], 3}] Block[{h}, h[{{a_, b_}, c_}] := {a, b, c}; h /@ data] All of the above return {{x1, y1, z1}, {x2, y2, z2}, {x3, y3, z3}, {x4, y4, z4}}


2

another option is Cases lst = {{{x1, y1}, z1}, {{x2, y2}, z2}} Cases[lst, {{x__}, y__} :> {x, y}]


5

You may be going to too much trouble here. Consider that Position works on a matrix just as well as a vector. You did not include values for your parameters, so I can't use your code, but take a look at the following example. I have a matrix selector that contains $0$ or $1$ entries, and I want to grab the elements of another matrix target that correspond ...



Top 50 recent answers are included