[Numpy-discussion] Inverting argsort(a, axis=0) to obtain column-wise ranks

John Schulman joschu@caltech....
Mon Sep 20 00:17:22 CDT 2010

Argsort twice and you get the rank.


That's because argsort is it's own inverse when applied to the ranks.

On Tue, Sep 7, 2010 at 1:01 PM, Alexander Michael <lxander.m@gmail.com> wrote:
> Calculating ranks by inverting the results of an argsort is
> straightforward and fast for 1D arrays:
> indices = argsort(a1)
> ranks = zeros_like(indices)
> ranks[indices] = arange(len(indices))
> I was wondering if there was an equally pithy way to do this for
> multiple data samples stored column-wise in a 2D array. That is, is
> there a trick to invert the results of argsort(a2, axis=0) without
> iterating (in python) over the columns?
> Thanks,
> Alex
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion

More information about the NumPy-Discussion mailing list