Numpy数组下降排序表(移动整列)

时间:2017-07-20 20:23:19

标签: python arrays sorting numpy

如何制作这个numpy数组:

[[   0.    1.    2.]
 [ 192.  312.  98.]]

按此分类:

[[   1.    0.    2.]  # Moves entire column instead of just the value in the second row
 [ 312.  192.  98.]]  # Highest to lowest

谢谢。

1 个答案:

答案 0 :(得分:3)

在第二行使用argsort,然后使用输出索引重新排序列:

a[:, a[1].argsort()[::-1]]
#array([[   1.,    0.,    2.],
#       [ 312.,  192.,   98.]])
相关问题