How to find maximum value in whole 2D array with indices
Here, You can test the max value using the index returned, indices returned should look like (array([0], dtype=int64), array([2], dtype=int64))
when you print the indices.
import numpy as np
a = np.array([[200,300,400],[100,50,300]])
indices = np.where(a == a.max())
print(a[indices]) # prints [400]
# Index for max value found two times (two locations)
a = np.array([[200,400,400],[100,50,300]])
indices = np.where(a == a.max())
print(a[indices]) # prints [400 400] because two indices for max
#Now lets print the location (Index)
for index in indices:
print(index)
Refer to this answer, which also elaborates how to find the max value and its (1D) index, you can use argmax()
>>> a = array([[10,50,30],[60,20,40]])
>>> maxindex = a.argmax()
>>> maxindex
3
You can then use unravel_index(a.argmax(), a.shape)
to get the indices as a tuple:
>>> from numpy import unravel_index
>>> unravel_index(a.argmax(), a.shape)
(1, 0)