[Numpy-discussion] Inverting argsort(a, axis=0) to obtain column-wise ranks
Alexander Michael
lxander.m@gmail....
Thu Sep 9 15:59:42 CDT 2010
Clever and concise (and expect that it works), but isn't this less
efficient? Sorting is O(n*log(n)), while the code I gave is O(n).
Using argsort has the potential to use less memory, though.
On Tuesday, September 7, 2010, Zachary Pincus <zachary.pincus@yale.edu> wrote:
>> indices = argsort(a1)
>> ranks = zeros_like(indices)
>> ranks[indices] = arange(len(indices))
>
> Doesn't answer your original question directly, but I only recently
> learned from this list that the following does the same as the above:
> ranks = a1.argsort().argsort()
> Will wonders never cease...
>
> So does ranks=a2.argsort(axis=0).argsort(axis=0) then do the trick?
>
> Zach
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
More information about the NumPy-Discussion
mailing list