Logical operation between two Boolean lists

前端 未结 7 2046
终归单人心
终归单人心 2021-02-07 15:58

I get a weird result and I try to apply the and or the or operator to 2 Boolean lists in python. I actually get the exact opposite of what I was expec

7条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-07 16:03

    If what you actually wanted was element-wise boolean operations between your two lists, consider using the numpy module:

    >>> import numpy as np
    >>> a = np.array([True, False, False])
    >>> b = np.array([True, True, False])
    >>> a & b
    array([ True, False, False], dtype=bool)
    >>> a | b
    array([ True,  True, False], dtype=bool)
    

提交回复
热议问题