a = np.arange(15)
# Method 1
index = np.where((a >= 5) & (a <= 10))
a[index]
# Method 2:
index = np.where(np.logical_and(a>=5, a<=10))
a[index]
# > (array([6, 9, 10]),)
# Method 3: (thanks loganzk!)
a[(a >= 5) & (a <= 10)]
numpy 数组元素筛选
最新推荐文章于 2024-05-28 20:30:18 发布