How do I make this numpy array:
[[ 0. 1. 2.]
[ 192. 312. 98.]]
Get sorted into this:
[[ 1. 0. 2.] # Moves entire column instead of just the value in the second row
[ 312. 192. 98.]] # Highest to lowest
Thank you.
How do I make this numpy array:
[[ 0. 1. 2.]
[ 192. 312. 98.]]
Get sorted into this:
[[ 1. 0. 2.] # Moves entire column instead of just the value in the second row
[ 312. 192. 98.]] # Highest to lowest
Thank you.
Use argsort
on the second row and then use the output indices to reorder columns:
a[:, a[1].argsort()[::-1]]
#array([[ 1., 0., 2.],
# [ 312., 192., 98.]])