I have three lists as such:
a = np.array([True, True, False, False])
b = np.array([False, False, False, False])
c = np.array([False, False, False, True])
I want to add the arrays so that the new array only has False
if all the corresponding elements are False
. For example, the output should be:
d = np.array([True, True, False, True])
However, d = np.add(a,b,c)
returns:
d = np.array([True, True, False, False])
Why is this and how can I fix it? Thanks!
np.add
's third parameter is an optional array to put the output into. The function can only add two arrays.
Just use the normal operators (and perhaps switch to bitwise logic operators, since you're trying to do boolean logic rather than addition):
d = a | b | c
If you want a variable number of inputs, you can use the any
function:
d = np.any(inputs, axis=0)
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