I want to generate an array with the index of the highest max value of each row.
a = np.array([ [1,2,3], [6,5,4], [0,1,0] ])
maxIndexArray = getMaxIndexOnEachRow(a)
print maxIndexArray
[[2], [0], [1]]
There's a np.argmax function but it doesn't appear to do what I want...
argmax() in Python. The numpy. argmax() function returns indices of the max element of the array in a particular axis.
Use the enumerate() function to find out the index of the maximum value in a list. Use the numpy. argmax() function of the NumPy library to find out the index of the maximum value in a list.
Now try to find the maximum element. To do this we have to use numpy. max(“array name”) function. For finding the minimum element use numpy.
Using ndenumerate() function to find the Index of value It is usually used to find the first occurrence of the element in the given numpy array.
The argmax()
function does do what you want:
print a.argmax(axis=1)
array([2, 0, 1])
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