Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

numpy check all elements are False [duplicate]

Tags:

python

numpy

I have a numpy 1-D array containing boolean values of True or False. I want to check whether all of them are False such that a single True/False is returned whether all elements in the numpy array are False or True

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

I looked into np.all(), but that does not see to solve my problem.

Thanks!

like image 848
Arun Avatar asked Sep 03 '26 00:09

Arun


1 Answers

Compare each item with False and then reduce using np.all

np.all(x == False)
like image 143
Dan D. Avatar answered Sep 04 '26 15:09

Dan D.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!