我想返回python numpy数组中两个值之间的所有值的索引。这是我的代码:
inEllipseIndFar = np.argwhere(excessPathLen * 2 < ePL < excessPathLen * 3)
但它返回一个错误:
inEllipseIndFar = np.argwhere((excessPathLen * 2 < ePL < excessPathLen * 3).all())
ValueError: The truth value of an array with more than one element is ambiguous. Use
a.any() or a.all()
我想知道是否有一种方法可以在不遍历数组的情况下执行此操作。谢谢!
通过使用圆括号和正确的操作,可以组合多个布尔表达式:
还可以将
np.where
的结果设置为变量以提取值:由于
> < =
返回屏蔽数组,因此可以将它们相乘以获得所需的效果(基本上是逻辑和):相关问题 更多 >
编程相关推荐