How do I find the row or column which contains the array-wide maximum value in a 2d numpy array?
If you only need one or the other:
np.argmax(np.max(x, axis=1))
for the column, and
np.argmax(np.max(x, axis=0))
for the row.
You can use np.argmax
along with np.unravel_index
as in
x = np.random.random((5,5))
print np.unravel_index(np.argmax(x), x.shape)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With