1

I have multiple bool np.ndarray of same shape, e.g.:

a1 = [T, F, F]
a2 = [F, F, T]
a3 = [F, T, F]

How can I apply the or operation maybe something like this and get the result [T, T, T]?

res = Or([a1, a2, a3])

1 Answer 1

2

If I understand correctly, you want this:

a1 = [True, False, False]
a2 = [False, False, True]
a3 = [False, True, False]
res = np.vstack([a1,a2,a3]).any(axis=0)

or equally:

res = np.logical_or.reduce([a1,a2,a3])

(I expect reduce to be faster or similar performance as stack). There are also many more ways to achieve this. I expect these to be faster than others.

output:

[ True  True  True]
Sign up to request clarification or add additional context in comments.

Comments

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.