[SciPy-user] How to use argmax ?

lorenzo bolla lbolla@gmail....
Tue Oct 23 02:39:58 CDT 2007


not sure if this is very efficient, but it works:

In [87]: a = numpy.random.rand(4,3)

In [88]: ind = a.argmax(axis=0)

In [89]: numpy.diag(a[ind])
Out[89]: array([ 0.62609397,  0.81456652,  0.86274995])

In [90]: a
Out[90]:
array([[ 0.46902428,  0.19723896,  0.25731427],
       [ 0.39632899,  0.81456652,  0.5836383 ],
       [ 0.62609397,  0.6931616 ,  0.86274995],
       [ 0.22968695,  0.22322129,  0.14708956]])

In [91]: a[ind]
Out[91]:
array([[ 0.62609397,  0.6931616 ,  0.86274995],
       [ 0.39632899,  0.81456652,  0.5836383 ],
       [ 0.62609397,  0.6931616 ,  0.86274995]])


L.

On 10/22/07, Daniel Lenski <dlenski@gmail.com> wrote:
>
> On Mon, 22 Oct 2007 19:04:54 +0000, Daniel Lenski wrote:
>
> > Or maybe this is what you're looking for:
> >
> >>>>> ind = a.argmax(axis=0)
> >>>>> a[ ind, [0,1,2] ]
> > array([60, 20, 14])
> >
> > ... which basically returns a[ind[0],0], a[ind[1],1], and a[ind[2],2].
> >
> > Dan
>
> Yeah, there really must be a straightforward, easy way to do this without
> explicitly listing the indices.  Hmmm...
>
> _______________________________________________
> SciPy-user mailing list
> SciPy-user@scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/scipy-user/attachments/20071023/27f0a442/attachment.html 


More information about the SciPy-user mailing list