How to xor all elements of a boolean numpy array using vectorized methods:
i.e., a_1 xor a_2 xor ... xor a_n
?
I would prefer using the xor ufunc I think, which is bitwise_xor
(or logical_xor
):
np.bitwise_xor.reduce(a)
or:
np.logical_xor.reduce(a)
One advantage is, you don't get bogus stuff for floats.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With