动机:在数值列表中,我尝试找到最小值的索引 - 附带条件,该值必须低于某个阈值。这是一个一切都按预期工作的示例
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
这是一个np.ma.argmin
发生意外的情况:
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
为什么会这样,我怎样才能让它返回None
?注意:设置fill_value = None
没有帮助。