0

Thanks in advance to those who take the time to answer this question. It is one of my first questions, so sorry if it is not formulated in the best way.

The question, as the title indicates, is how I could obtain the indices that each element of a matrix would have if it were ordered. For example:

x = array ([3,8,1,21,7,65,2])

The expected output would be:

array ([2, 4, 0, 5, 3, 6, 1])

Of course most of the examples I have come across refer to the argsort() function, however it does not return the expected output, it returns:

array([2, 6, 0, 4, 1, 3, 5])

As you can see, the output is different. Testing and looking for the best I have found is to apply argsort() twice, that is, argsort(argsort (x)), however I am surprised that it is not necessary to apply a function twice and there is no more direct / simple method, for other side I would like to know if there is a direct way to get what I want and what would be the best / most efficient approach to tackle this task.

  • Why is that your expected output? Surely it should be: `array([2, 6, 0, 4, 1, 3, 5])` ? (which is what `np.argsort(x)` will return...) – Jon Clements Jun 19 '21 at 16:15
  • @Jon Clements, Sorry for the confusion, my fault, in the second example (the output returned by argsort (x) which is the one I DO NOT want instead of putting the result of argsort I have accidentally re-copied the initial array). The output I really want is the first one, that is, the indices that each element of the initial array (x) would have if it were ordered. I have already corrected the question. Thanks – pyGisServer Jun 19 '21 at 16:27
  • As far as I'm aware then - double `argsort` is as good as it gets... – Jon Clements Jun 19 '21 at 16:29

0 Answers0