cf.DomainAncillary.round¶
-
DomainAncillary.
round
(decimals=0, i=False)[source]¶ evenly round elements of the data array to the given number of decimals.
Note
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 :
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.
- i:
bool
, optional If True then update the domain ancillary in place. By default a new domain ancillary is created. In either case, a domain ancillary is returned.
int
, optionalReturns: - out : cf.DomainAncillary
The domain ancillary with rounded data array values.
Examples: >>> print f.array [-1.81, -1.41, -1.01, -0.91, 0.09, 1.09, 1.19, 1.59, 1.99]) >>> print f.round().array [-2., -1., -1., -1., 0., 1., 1., 2., 2.] >>> print f.round(1).array [-1.8, -1.4, -1. , -0.9, 0.1, 1.1, 1.2, 1.6, 2. ] >>> print f.round(-1).array [-0., -0., -0., -0., 0., 0., 0., 0., 0.]