Motivation: in a list of numeric values I try to find the index of the smallest value - with the side condition, that the value has to below a certain treshold. Here is an example where everything works as expected
import numpy as np
a = np.array([1, 5, -4])
threshold = 3
b = np.ma.MaskedArray(a, a >= threshold)
np.ma.argmin(b) # returns 2, since a[2] is -4 which is the smallest element < 3
Here is a case where np.ma.argmin
does something unexpected:
a = np.array([4, 5])
threshold = 3
b = np.ma.MaskedArray(a, a >= threshold)
np.ma.argmin(b) # returns 0, expected a None etc. since there is no element < 3
Why is this and how can I make it return None
? Note: setting fill_value = None
did not help.