Evenly round to the given number of decimals.
Parameters: | a : array_like
decimals : int, optional
out : ndarray, optional
|
---|---|
Returns: | rounded_array : ndarray
|
See also
Notes
For values exactly halfway between rounded decimal values, Numpy rounds 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 [16] and errors introduced when scaling by powers of ten.
References
[16] | “Lecture Notes on the Status of IEEE 754”, William Kahan, http://www.cs.berkeley.edu/~wkahan/ieee754status/IEEE754.PDF |
[17] | “How Futile are Mindless Assessments of Roundoff in Floating-Point Computation?”, William Kahan, http://www.cs.berkeley.edu/~wkahan/Mindless.pdf |
Examples
>>> np.around([.5, 1.5, 2.5, 3.5, 4.5])
array([ 0., 2., 2., 4., 4.])
>>> np.around([1,2,3,11], decimals=1)
array([ 1, 2, 3, 11])
>>> np.around([1,2,3,11], decimals=-1)
array([ 0, 0, 0, 10])