I want to sort the array
a = {{{1, 0, 0}, {1, 1, 1}, {0.5, 0.0, 0.5}}, {{-1}, {1}, {-1}}}
in the following way:
a[[1]] and a[[2]] have one-to-one correspondence; Sort a[[2]] from small to great value, at the same time, the sequence of a[[1]] will be rearranged accordingly.
In the end, I want to get a new array as
{{{1, 0, 0}, {0.5, 0.0, 0.5}, {1, 1, 1}}, {{-1}, {-1}, {1}}}
Is there some simple way to realized this in Mathematica?
I appreciate your help!
SortBy? – Edmund Jul 28 '16 at 17:50Transpose@*SortBy[Last]@*Transpose@a? – JungHwan Min Jul 28 '16 at 17:53a = #[[Ordering[Last@a]]] & /@ a– N.J.Evans Jul 28 '16 at 18:58SortByto get your output I believe:SortBy[a\[Transpose], {Last}]\[Transpose]– Mr.Wizard Jul 28 '16 at 19:09