Python AND operator on two boolean lists - how?

前端 未结 9 2146
感动是毒
感动是毒 2020-11-28 09:36

I have two boolean lists, e.g.,

x=[True,True,False,False]
y=[True,False,True,False]

I want to AND these lists together, with the expected o

9条回答
  •  星月不相逢
    2020-11-28 10:30

    Instead of using

    [a and b for a, b in zip(x, y)]
    

    one could just use the possibility of numpy to multiply bool-values:

    (np.array(x)*np.array(y))
    >> array([ True, False, False, False], dtype=bool)
    

    Or do I overlook a special case?

提交回复
热议问题