Boolean operators with Numpy

PHOTO EMBED

Thu Nov 25 2021 08:45:11 GMT+0000 (UTC)

Saved by @Sourabh #numpy #booleans_in_numpy

# Create arrays
import numpy as np
my_house = np.array([18.0, 20.0, 10.75, 9.50])
your_house = np.array([14.0, 24.0, 14.25, 9.0])

# my_house greater than 18.5 or smaller than 10
print(np.logical_or(my_house >18.5, my_house < 10))

# Both my_house and your_house smaller than 11
print(np.logical_and(my_house < 11, your_house < 11))
content_copyCOPY

To use these operators with Numpy, you will need np.logical_and(), np.logical_or() and np.logical_not().