5.9. Logical operators#

We already learned Python’s logical operators not, or and and. Unfortunately, these operators work only on bool, not on arrays of bool. However, NumPy provides equivalents:

Python’s operator on bool

NumPy’s equivalent operator for arrays of bool

not

~

or

|

and

&

Fig. 5.8 illustrates the behaviour of each operator.

Logical operators on Python and Numpy

Fig. 5.8 Correspondence between logical operations on bool and ndarray.#