[Numpy-discussion] how to use argsort result?

Emanuele Olivetti olivetti at itc.it
Tue Jul 11 04:32:48 CDT 2006


Hi,
I don't understand how to use argsort results. I have a 2D matrix and
I want to sort values in each row and obtain the index array of that
sorting. Argsort(1) is what I need, but the problem is how to use its
result in order to obtain a sorted matrix. Here is the simple example:

A = array([[2,3,1],[5,4,6]])
indexes = a.argsort(1)

now indexes is:
array([[2, 0, 1],
        [1, 0, 2]])

I'd like to apply indexes to A and obtain:
array([[1, 2, 3],
        [4, 5, 6]])

or better, I'm interested both in a subset of indexes, i.e. indexes[:,1:], and
the related values of A matrix.

How can I do this? If I simpy say: A[indexes] I get an IndexError.

Thanks in advance,

Emanuele

P.S. numpy.__version__ is '0.9.8'.




More information about the Numpy-discussion mailing list