0

I have a simple python code segment that intended to sort each row of a 2D numpy matrix

>>> import numpy as np
>>> X=np.random.random((3,3))
>>> X
array([[ 0.57758986,  0.76771506,  0.94539164],
       [ 0.37619117,  0.85602478,  0.21527702],
       [ 0.41134957,  0.47028597,  0.0672778 ]])
>>> X.argsort(axis=-1)
array([[0, 1, 2],
       [2, 0, 1],
       [2, 0, 1]], dtype=int64)

What I am trying to do is sorting on each row so that I can get the order of each row from min to max, so I am expecting the output of X.argsort to be:

array([[0, 1, 2],
       [1, 2, 0],
       [1, 2, 0]], dtype=int64)

However definitely argsort does not work in this way, do I have any mis-understanding of the argsort of numpy?

Thanks for any suggestions!

Roy Li
  • 51
  • 9

0 Answers0