Hi, On Tue, Jan 15, 2013 at 1:50 PM, Mads Ipsen <madsip...@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, > > Mads > > -- > +-----------------------------------------------------+ > | Mads Ipsen | > +----------------------+------------------------------+ > | Gåsebæksvej 7, 4. tv | | > | DK-2500 Valby | phone: +45-29716388 | > | Denmark | email: mads.ip...@gmail.com | > +----------------------+------------------------------+ > > > > _______________________________________________ > NumPy-Discussion mailing list > NumPy-Discussion@scipy.org > http://mail.scipy.org/mailman/listinfo/numpy-discussion > >
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion