Rounding and Precision
round, floor, ceil and trunc handle decimals. Floating point numbers are approximate, so compare with isclose.
Example
import numpy as np
a = np.array([1.234, 2.567])
print(np.round(a, 1), np.floor(a), np.ceil(a))
print(0.1 + 0.2 == 0.3, np.isclose(0.1 + 0.2, 0.3))Result
[1.2 2.6] [1. 2.] [2. 3.] False True
Exercise
Compare floats safely.
np.(a, b)
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.