0

I have a python array of this shape [3, 1000, 3] with boolean values inside. The first 3 is the batch size and the values of a batch are like these

[[False, False, False]\n
 [False, True, True]\n
 [False, False, True]\n
 [True, True, True]\n
 ...
]
size (1000, 3)

I want to apply the and function to each triplet to end up with this new array

[[False]\n
 [False]\n
 [False]\n
 [True]\n
 ...
]
size (3, 1000)

Looking at numpy I didn't find something useful. I've also tried to import operator and apply reduce(operator.and_, array) but it doesn't work.

Any idea to solve this?

1 Answer 1

2

You can easily do this using np.all. This will check if all values along the last dimension are True:

y = np.all(arr, axis=-1)
y.shape # (3, 1000)
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.