# [Numpy-discussion] argsort

eat e.antero.tammi@gmail....
Tue Jan 15 14:53:39 CST 2013

```Hi,

On Tue, Jan 15, 2013 at 1:50 PM, Mads Ipsen <madsipsen@gmail.com> wrote:

>  Hi,
>
> I simply can't understand this. I'm trying to use argsort to produce
> indices that can be used to sort an array:
>
>   from numpy import *
>
>   indices = array([[4,3],[1,12],[23,7],[11,6],[8,9]])
>   args = argsort(indices, axis=0)
>   print indices[args]
>
> gives:
>
> [[[ 1 12]
>   [ 4  3]]
>
>  [[ 4  3]
>   [11  6]]
>
>  [[ 8  9]
>   [23  7]]
>
>  [[11  6]
>   [ 8  9]]
>
>  [[23  7]
>   [ 1 12]]]
>
> I thought this should produce a sorted version of the indices array.
>
> Any help is appreciated.
>
Perhaps these three different point of views will help you a little bit
more to move on:
In []: x
Out[]:
array([[ 4,  3],
[ 1, 12],
[23,  7],
[11,  6],
[ 8,  9]])
In []: ind= x.argsort(axis= 0)
In []: ind
Out[]:
array([[1, 0],
[0, 3],
[4, 2],
[3, 4],
[2, 1]])

In []: x[ind[:, 0]]
Out[]:
array([[ 1, 12],
[ 4,  3],
[ 8,  9],
[11,  6],
[23,  7]])

In []: x[ind[:, 1]]
Out[]:
array([[ 4,  3],
[11,  6],
[23,  7],
[ 8,  9],
[ 1, 12]])

In []: x[ind, [0, 1]]
Out[]:
array([[ 1,  3],
[ 4,  6],
[ 8,  7],
[11,  9],
[23, 12]])
-eat

>
> Best regards,
>
>
>  --
> +-----------------------------------------------------+
> +----------------------+------------------------------+
> | Gåsebæksvej 7, 4. tv |                              |
> | DK-2500 Valby        | phone:          +45-29716388 |
> | Denmark              | email:  mads.ipsen@gmail.com |
> +----------------------+------------------------------+
>
>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20130115/b50737ff/attachment.html
```