cf.Data.round¶
-
Data.
round
(decimals=0, inplace=False, i=False)[source]¶ Evenly round elements of the data array to the given number of decimals.
Values exactly halfway between rounded decimal values are rounded to the nearest even value. Thus 1.5 and 2.5 round to 2.0, -0.5 and 0.5 round to 0.0, etc. Results may also be surprising due to the inexact representation of decimal fractions in the IEEE floating point standard and errors introduced when scaling by powers of ten.
New in version 1.1.4.
- Parameters
- decimals
int
, optional Number of decimal places to round to (default: 0). If decimals is negative, it specifies the number of positions to the left of the decimal point.
- inplace:
bool
, optional If True then do the operation in-place and return
None
.- i: deprecated at version 3.0.0
Use the inplace parameter instead.
- decimals
- Returns
Examples
>>> d = cf.Data([-1.81, -1.41, -1.01, -0.91, 0.09, 1.09, 1.19, 1.59, 1.99]) >>> print(d.array) [-1.81 -1.41 -1.01 -0.91 0.09 1.09 1.19 1.59 1.99] >>> print(d.round().array) [-2., -1., -1., -1., 0., 1., 1., 2., 2.] >>> print(d.round(1).array) [-1.8, -1.4, -1. , -0.9, 0.1, 1.1, 1.2, 1.6, 2. ] >>> print(d.round(-1).array) [-0., -0., -0., -0., 0., 0., 0., 0., 0.]