This function returns the truncated value of the input array elements. The truncated value t of input value x is the nearest integer which is closer to zero than x.
The fractional part of the input number is discarded by this function.
numpy.trunc(array)
An array containing the truncated values are to be returned.
import numpy as np arr = [0.23, 0.09, 1.2, 1.24, 9.99] print("Input array:",arr) r_arr = np.trunc(arr) print("Output array:",r_arr) arr2 = [145.23, 0.12, 12.34, 123] r_arr2=np.trunc(arr2) print("Input array:",arr2) print("Output array:",r_arr2)
Output: