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

Alan G Isaac aisaac at american.edu
Wed Oct 18 10:47:30 CDT 2006


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.


Untested:
def arrayMaxInd(data):
        a = asarray(data)
        argmax1d = a.argmax()
        rs,cs = a.shape
        r,c = argmax1d//cs, argmax1d%cs
        return (r,c,argmax1d)

hth,
Alan Isaac







More information about the SciPy-user mailing list