![](/img/trans.png)
[英]Is there a nice way to check if numpy array elements are within a range?
[英]Check if number in numpy array is within range specified in another array
數據
a = np.array([[0.5,1,50],[0.5,1,30]])
b = np.array([[0.40,0.60],[0.75,2.0],[40,70]])
預期成績:
TRUE
FALSE
如果我只有幾行,一個愚蠢的方法是:
if b[0][0] <= a[0][0] <= b[0][1] and b[1][0] <= a[0][1] <= b[1][1] and b[2][0] <= a[0][2] <= b[2][1]:
print("its b!!")
IIUC,這是一種方法:
result = np.apply_along_axis(lambda x: all((x > b.T[0]) & (x < b.T[-1])), 1, a)
輸出:
array([ True, False])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.