Joe Flip Joe Flip - 16 days ago 6
Python Question

Python: Adding boolean Numpy arrays

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!

v2b v2b
Answer
>>> a=[True, True, False, False]
>>> b=[False, False, False, False]
>>> c=[False, False, False, True]
>>> map(sum, zip(a,b,c))
[1, 1, 0, 1]
>>>