views:

49

answers:

1

How can I get get the position of the biggest item in an numpy array?

+5  A: 

The argmax() method should help.

Update

(After reading comment) I believe the argmax() method would work for multi dimensional arrays as well. The linked documentation gives an example of this:

>>> a = array([[10,50,30],[60,20,40]])
>>> maxindex = a.argmax()
>>> maxindex
3

Update 2

(Thanks to KennyTM's comment) You can use unravel_index(a.argmax(), a.shape) to get the index as a tuple:

>>> from numpy import unravel_index
>>> unravel_index(a.argmax(), a.shape)
(1, 0)
Manoj Govindan
But i have a multidimensional array.
kame
@kame: updated answer. See above.
Manoj Govindan
Use `unravel_index(a.argmax(), a.shape)` to get the index as a tuple.
KennyTM
what does number 3 mean? Okay i see. I was looking for (1,0).
kame
@KenntyTM: Thanks! I didn't know that.
Manoj Govindan
@KennyTM Thank you!
kame