[SciPy-user] More elegant way to get indices of the max value in an?array?
Stefan van der Walt
stefan at sun.ac.za
Wed Oct 18 11:13:50 CDT 2006
On Wed, Oct 18, 2006 at 11:47:30AM -0400, Alan G Isaac wrote:
> On Wed, 18 Oct 2006, Holden Chase apparently wrote:
> > I would like to get the array indices of the max value in an array. Is
> > there a more elegant way than what I have implemented below using
> > argmax()? This routine returns the indices and the max value.
> def arrayMaxInd(data):
> a = asarray(data)
> argmax1d = a.argmax()
> rs,cs = a.shape
> r,c = argmax1d//cs, argmax1d%cs
> return (r,c,argmax1d)
How about numpy.unravel_index?
More information about the SciPy-user