Applying np.argsort() to an numpy array with repeated elements

51 Views Asked by At

What is the order of indexes for each element after applying np.argsort() to an array with repeated values?

np.argsort(np.array([5, 2, 3, 4, 5, 0, 3, 2, 5, 3, 2, 0, 5, 0, 5, 5, 0, 5, 0, 1, 3, 4, 3, 4, 3, 3, 2, 2, 3, 2, 3, 5, 0, 0, 0, 5, 2, 3, 0, 1, 0, 3, 2, 2, 2, 0, 5, 0, 0, 3, 3, 2, 2, 2, 0, 1, 5, 4, 4, 0, 3, 5, 2, 5, 5, 2, 1, 5, 1, 0, 2, 5, 0, 5, 2, 5, 3, 4, 5, 3, 0, 3, 2, 0, 2, 0]))

gives:

 [85 33 32 40 45 47 48 54 18 34 16 59 13 38 72 11 83 69 80  5 39 55 19 68 66 52 51 65 70 74 44 43 84 82 53 62 42  7  1 10 29 36 27 26  9 76 60 79 20  6 22 37 50  2 30 41 81 28 25 24 49 58 23 77  3 57 21 78 75  4 73 61 8 67 12 64 63 14 15 56 17 46 31 35 71  0]

For example, in the original array, 0 starts as 5th element and then 11th, 13th,... Why does the resulted argsort array start by indexes 85, 33, 32, 40, 47,... instead of 5, 11, 13, 16, 18, 32, 33, 34, 38, 40 ...?

0

There are 0 best solutions below