Is there a way to get max and argmax by one stroke ?
import numpy as np
a=[0,0,1,0]
maximum=max(a)
index=np.argmax(a)
Is there a fastest way to do it, with something like:
[maximum,index]=function(a)
Essentially, the argmax function returns the index of the maximum value of a Numpy array. What is this? It's somewhat similar to the Numpy maximum function, but instead of returning the maximum value, it returns the index of the maximum value.
The argmax function returns the argument or arguments (arg) for the target function that returns the maximum (max) value from the target function.
argmax() function returns the indices of the maximum values along an axis. In case of multiple occurrences of the maximum values, the indices corresponding to the first occurrence will be returned.
There is argmin() and argmax() provided by numpy that returns the index of the min and max of a numpy array respectively.
Maybe something like this is faster...
index = np.argmax(a)
max = a[index]
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