trunc¶
-
trunc(x, out=None, **kwargs)¶ Return the truncated value of the input, element-wise. The truncated value of the scalar x is the nearest integer i which is closer to zero than x is. In short, the fractional part of the signed number x is discarded.
Parameters: - x : ndarray or scalar
Input data.
- out : ndarray or None, optional
A location into which the result is stored.
Returns: - y : ndarray or scalar
The truncated value of each element in x. This is a scalar if x is a scalar.
- Notes
- This function differs from the original numpy.trunc in the following aspects:
- Do not support where, a parameter in numpy which indicates where to calculate.
- Cannot cast type automatically. Dtype of out must be same as the expected one.
- Cannot broadcast automatically. Shape of out must be same as the expected one.
- If x is plain python numeric, the result won’t be stored in out.
Examples
>>> a = np.array([-1.7, -1.5, -0.2, 0.2, 1.5, 1.7, 2.0]) >>> np.trunc(a) array([-1., -1., -0., 0., 1., 1., 2.])