本文翻译自:Sorting arrays in NumPy by column
How can I sort an array in NumPy by the nth column? 如何按第n列对NumPy中的数组排序?
For example, 例如,
a = array([[9, 2, 3],
[4, 5, 6],
[7, 0, 5]])
I'd like to sort rows by the second column, such that I get back: 我想按第二列对行进行排序,以便返回:
array([[7, 0, 5],
[9, 2, 3],
[4, 5, 6]])
#1楼
参考:https://stackoom.com/question/Brhr/按列对NumPy中的数组排序
#2楼
I suppose this works: a[a[:,1].argsort()]
我想这a[a[:,1].argsort()]
: a[a[:,1].argsort(