Perform element-wise arithmetic, comparisons, and math functions on entire arrays at once.
Array Operations (Vectorised)
import numpy as np
a = np.array([1, 2, 3, 4])
b = np.array([10, 20, 30, 40])
# Element-wise arithmetic (no Python loops!)
a + b # [11 22 33 44]
a * b # [10 40 90 160]
a ** 2 # [1 4 9 16]
a / 2 # [0.5 1. 1.5 2.]
b - a # [9 18 27 36]
# Scalar operations
a + 10 # [11 12 13 14]
a * 3 # [3 6 9 12]
# Comparison (returns boolean array)
a > 2 # [False False True True]
a == 1 # [True False False False]
# Math functions
np.sqrt(a) # [1. 1.41 1.73 2.]
np.log(a) # natural log
np.exp(a) # e^x
np.abs(a) # absolute value