undo or reverse argsort(), python

Posted by Vincent on Stack Overflow See other posts from Stack Overflow or by Vincent
Published on 2010-03-20T15:55:37Z Indexed on 2010/03/20 16:01 UTC
Read the original article Hit count: 141

Filed under:
|
|
|

Given an array 'a' I would like to sort the array by columns "a.sort(axis=0)" do some stuff to the array and then undo the sort. By that I don't mean re sort but basically reversing how each element was moved. I assume argsort() is what I need but it is not clear to me how to sort an array with the results of argsort() or more importantly apply the reverse/inverse of argsort()

Here is a little more detail

I have an array a, shape(a) = rXc I need to sort each column

aargsort = a.argsort(axis=0)  # May use this later
aSort = a.sort(axis=0)

now average each row

aSortRM = asort.mean(axis=1)

now replace each col in a row with the row mean. is there a better way than this

aWithMeans = ones_like(a)
for ind in range(r)  # r = number of rows
    aWithMeans[ind]* aSortRM[ind]

Now I need to undo the sort I did in the first step. ????

© Stack Overflow or respective owner

Related posts about python

Related posts about numpy