6.numpy_Coparision_operators
6.numpy_Coparision_operators
In [18]: x = np.random.randint(10,size=(3,4))
print(x)
print(np.count_nonzero(x<7))
print(np.sum(x<7))
print(np.sum(x<7,axis=1))
print(np.all(x==7))
print(np.all(x>0))
# is there any nubers greater than 0
print(np.any(x>0))
# boolean operators :
print(np.sum((x>3) & (x<8)))
# similarly | - for or ; ^ - for xor ; ~ - for not
[[7 3 2 5]
[2 5 8 7]
[1 8 3 2]]
8
8
[3 2 3]
False
True
True
4
[[7 7 3 1]
[8 6 3 8]
[8 4 4 7]]
[[False False True True]
[False False True False]
[False True True False]]
[3 1 3 4 4]
# Subtracting 172 from each element in the array shifts the range, centering aro
localhost:8892/doc/tree/numpy_Coparision_operators.ipynb? 1/2
07/02/2025, 21:03 numpy_Coparision_operators
# The comparison < 90 checks if each day is within 90 days of the shifted center
# s = (np.arange(365) - 172 < 90) #
# print(s)
localhost:8892/doc/tree/numpy_Coparision_operators.ipynb? 2/2