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]])
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]])
np.sort(a, axis=0)
would be a satisfactory solution for the given matrix. I suggested an edit with a better example but was rejected, although actually the question would be much more clear. The example should be something likea = numpy.array([[1, 2, 3], [6, 5, 2], [3, 1, 1]])
with desired outputarray([[3, 1, 1], [1, 2, 3], [6, 5, 2]])
– David