[SciPy-user] More elegant way to get indices of the max value in an?array?

P GM pgmdevlist at gmail.com
Wed Oct 18 11:44:37 CDT 2006


> How about numpy.unravel_index?

Sweet ! I didn't know this function existed ! Thx a lot.
So that gives us:

def argmax_coords(data):
    data = numpy.asarray(data)
    imax = data.argmax()
    return list(numpy.unravel_index(imax,data.shape) + [data.max(),]

On 10/18/06, Alan G Isaac <aisaac at american.edu> wrote:
> On Wed, 18 Oct 2006, alan wrote
> > return (r,c,argmax1d)
>
> That should have been a[r][c] or a[r,c] of course.
> But better ideas have been floated.
>
> Cheers,
> Alan
>
> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user
>


More information about the SciPy-user mailing list