I need to find the index of more than one minimum values that occur in an array. I am pretty known with np.argmin
but it gives me the index of very first minimum value in a array. For example.
a = np.array([1,2,3,4,5,1,6,1])
print np.argmin(a)
This gives me 0, instead I am expecting, 0,5,7.
Thanks!
Use the Array. indexOf() method to get the index of the min value. The indexOf method returns the index of the first occurrence of the value in the array.
The numpy argmin() function takes arr, axis, and out as parameters and returns the array. To find the index of a minimum element from the array, use the np. argmin() function.
Use min() and list. index() Functions to Get the Smallest Index of the List. In Python, the min() method will return the smallest value of the defined list.
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.
This should do the trick:
a = np.array([1,2,3,4,5,1,6,1])
print np.where(a == a.min())
argmin doesn't return a list like you expect it to in this case.
Maybe
mymin = np.min(a)
min_positions = [i for i, x in enumerate(a) if x == mymin]
It will give [0,5,7].
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