Following this trick to grab unique entries for a NumPy array, I now have a two-column array, basically of pairs with first element in the range [0.9:0.02:1.1] and the second element in the range [1.5:0.1:2.0]. Let's call this A
. Currently, it's completely unsorted, i.e.
In [111]: A
Out[111]:
array([[ 1.1 , 1.9 ],
[ 1.06, 1.9 ],
[ 1.08, 1.9 ],
[ 1.08, 1.6 ],
[ 0.9 , 1.8 ],
...
[ 1.04, 1.6 ],
[ 0.96, 2. ],
[ 0.94, 2. ],
[ 0.98, 1.9 ]])
I'd like to sort it so that each row first increases in the second column, then the first. i.e.
array([[ 0.9 , 1.5 ],
[ 0.9 , 1.6 ],
[ 0.9 , 1.7 ],
[ 0.9 , 1.9 ],
[ 0.9 , 1.9 ],
[ 0.9 , 2. ],
[ 0.92, 1.5 ],
...
[ 1.08, 2. ],
[ 1.1 , 1.5 ],
[ 1.1 , 1.6 ],
[ 1.1 , 1.7 ],
[ 1.1 , 1.8 ],
[ 1.1 , 1.9 ],
[ 1.1 , 2. ]])
but I can't find a sort algorithm that gives both. As suggested here, I've tried A[A[:,0].argsort()]
and A[A[:,1].argsort()]
, but they only sort one column each. I've also tried applying both but the same thing happens.
I apologize if I've missed something simple but I've been looking for this for a while now...