numpy 检查所有元素是否为 False

Aru*_*run 6 python numpy

我有一个numpy一维数组,其中包含Trueor的布尔值False。我想检查是否所有的元素都返回False一个,无论数组中的所有元素是 False 还是 TrueTrue/Falsenumpy

x = np.array([False, False, False])  # this should return True, since all values are False
y = np.array([True, True, True])  # this should return False, since all values are True
z = np.array([True, False, True]) # this should return False, since not all values are False
Run Code Online (Sandbox Code Playgroud)

我调查过np.all(),但这并不能解决我的问题。

谢谢!

Dan*_* D. 9

比较每个项目False,然后减少使用np.all

np.all(x == False)
Run Code Online (Sandbox Code Playgroud)

  • 也许只是`(~x).all()`? (3认同)