3

I'm trying to do an "&" operation across all the values in a simple bool array. The array I have is as follows:

array([False False True], dtype=bool) 

The only thing I've come up with is to slice out the values in the array and use "&" to give a "False" result. I feel like there must be a better way but I don't know enough about numpy to use it properly.

1
  • 1
    Just FYI, this operation is not bitwise in memory, but rather bytewise, since boolean variables take up a full byte each :/. You can do true bitwise operations on e.g. np.uint8 variables however using the operators &, |, <<, >> if necessary. Commented Aug 19, 2014 at 6:12

1 Answer 1

2

Use arr.all(), which is the same as np.all(arr):

import numpy as np
arr = np.array([False, False, True], dtype=bool) 
arr.all()
=> False
np.all(arr)
=> False
Sign up to request clarification or add additional context in comments.

1 Comment

For completeness, the converse of np.all is np.any.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.