0

I have a numpy array:

a = np.array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 2, 2, 2, 2])

and I'm using argsort function to short this array

a.argsort()

the result that I got was

array([ 0, 10, 8, 7, 6, 9, 4, 3, 2, 1, 5, 18, 16, 17, 19, 11, 12, 13, 14, 15], dtype=int64)

While the expected result should be:

array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 16, 17, 18, 19, 11, 12, 13, 14, 15], dtype=int64)

I have tried also to reduce the array to be less than 16 members and it was working well. Is there something wrong with argsort function?

coek34
  • 1
  • 1
  • As per the docs, use : `mergesort` for kind - http://docs.scipy.org/doc/numpy/reference/generated/numpy.argsort.html – Divakar Aug 04 '16 at 11:45
  • Maybe a better dup : http://stackoverflow.com/questions/26306011/sort-numpy-array-by-row-and-order-matching-values-based-on-original-array – Divakar Aug 04 '16 at 11:47
  • Great. Thank you. I'm not aware of this kind stuff. – coek34 Aug 04 '16 at 11:53

0 Answers0