I have a 2 dimensional NumPy array. I know how to get the maximum values over axes:
>>> a = array([[1,2,3],[4,3,1]]) >>> amax(a,axis=0) array([4, 3, 3])
How can I get the indices of the maximum elements? I would like as output array([1,1,0])
instead.
Python Numpy – Get Maximum Value of Array Given a numpy array, you can find the maximum value of all the elements in the array. To get the maximum value of a Numpy Array, you can use numpy function numpy. max() function.
>>> a.argmax(axis=0) array([1, 1, 0])
>>> import numpy as np >>> a = np.array([[1,2,3],[4,3,1]]) >>> i,j = np.unravel_index(a.argmax(), a.shape) >>> a[i,j] 4
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