Skip to content
Justice Tech School

Universal Functions

ufuncs such as sqrt, exp, log, sin and abs apply to every element quickly. Many have out and where options.

Example
import numpy as np
a = np.array([1, 4, 9])
print(np.sqrt(a), np.exp([0, 1]))
print(np.log([1, np.e]))
print(np.abs([-3, 2]), np.round(3.14159, 2))

Result

[1. 2. 3.] [1.         2.71828183]
[0. 1.]
[3 2] 3.14

Exercise

Take square roots.

np.(a)

Quiz Test

What is a ufunc?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.