Element-wise Math
Operators and ufuncs work on every item without loops.
Example
a = np.array([1, 2, 3])
print(a + 1, a * a, a ** 2)
print(np.sqrt([1, 4, 9]), np.exp(0), np.abs([-2, 3]))Result
[2 3 4] [1 4 9] [1 4 9] [1. 2. 3.] 1.0 [2 3]
Exercise
Square root.
np.([4, 9])
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.