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

Alexander Michael lxander.m@gmail....
Tue Sep 7 15:01:31 CDT 2010

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?


More information about the NumPy-Discussion mailing list