How can I get get the position (indices) of the largest value in a multi-dimensional NumPy array?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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:Update 2
(Thanks to KennyTM‘s comment) You can use
unravel_index(a.argmax(), a.shape)to get the index as a tuple: