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
2010-08-27 12:48:56
But i have a multidimensional array.
kame
2010-08-27 12:51:04
@kame: updated answer. See above.
Manoj Govindan
2010-08-27 12:53:35
Use `unravel_index(a.argmax(), a.shape)` to get the index as a tuple.
KennyTM
2010-08-27 12:57:07
what does number 3 mean? Okay i see. I was looking for (1,0).
kame
2010-08-27 12:58:20
@KenntyTM: Thanks! I didn't know that.
Manoj Govindan
2010-08-27 12:58:45
@KennyTM Thank you!
kame
2010-08-27 13:00:22