Sorting arrays in NumPy by column

后端 未结 13 2221
既然无缘
既然无缘 2020-11-22 03:47

How can I sort an array in NumPy by the nth column?

For example,

a = array([[9, 2, 3],
           [4, 5, 6],
           [7, 0, 5]])

相关标签:
13条回答
  • 2020-11-22 04:39

    I suppose this works: a[a[:,1].argsort()]

    This indicates the second column of a and sort it based on it accordingly.

    0 讨论(0)
提交回复
热议问题