Rounding
round, floor, ceil and trunc change decimals. astype(int) truncates.
Example
a = np.array([1.234, 2.5, -1.7])
print(a.round(1), np.floor(a), np.ceil(a), np.trunc(a))
print(np.round([0.5, 1.5, 2.5]))Result
[ 1.2 2.5 -1.7] [ 1. 2. -2.] [ 2. 3. -1.] [ 1. 2. -1.] [0. 2. 2.]
Exercise
Round down.
np.(a)
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.