1

so possort([100,50,200,5,150]) would return

[2,1,4,0,3]

I know argsort would give:

[3,1,0,4,2] 

and then I could just do

for i,j in enumerate(a):
    x[j]=i

but that seems clumsy and slow

kabanus
  • 24,623
  • 6
  • 41
  • 74
  • 1
    Not sure you have your dupe-hammer pointed in the right direction @Divakar. Looks more like he wants, for `idx = np.argsort(arr)`, `possort = idx[idx[idx]]` – Daniel F Sep 06 '18 at 09:30
  • @DanielF I went with the posted code, with `a` as `[3,1,0,4,2] `. Seems like thats what OP wanted. – Divakar Sep 06 '18 at 09:32
  • @Divakar The result should be `[2,1,4,0,3]`, I think @DanielF is correct. – kabanus Sep 06 '18 at 09:34
  • Nah, I'm not just tested it with another data set. I know it's some trick like that though. – Daniel F Sep 06 '18 at 09:35
  • @kabanus From the second link : `argsort_unique(np.array([3,1,0,4,2]))` is `array([2, 1, 4, 0, 3])`. – Divakar Sep 06 '18 at 09:36
  • @Divakar ah I see now, thanks for clarifying. – kabanus Sep 06 '18 at 09:37
  • Now I remember, it's `possort(x) = np.argsort(np.argsort(x))` – Daniel F Sep 06 '18 at 09:40
  • 1
    And the actual duplicate is [here](https://stackoverflow.com/questions/35136244/how-can-you-get-the-order-back-after-using-argsort?rq=1) – Daniel F Sep 06 '18 at 09:40
  • There is [a proposal to add such a function](https://github.com/numpy/numpy/issues/9880) – Eric Sep 06 '18 at 15:55
  • Thanks, I honestly tried searching for this until I got sick of having to prove I was a human for searching so many times. I suppose its tough since I cant think of a specific term to refer to what I'm looking for as opposed to what argsort gives. the argsort(argsort(x)) magic is a great trick! – Pax SpaceGoat Sep 07 '18 at 02:45

0 Answers0