官网参考:
https://docs.scipy.org/doc/numpy/reference/generated/numpy.round_.html
https://docs.scipy.org/doc/numpy/reference/generated/numpy.around.html#numpy.around
numpy.round_(a, decimals=0, out=None)
Round an array to the given number of decimals.
See also
around
equivalent function; see for details.
numpy.around(a, decimals=0, out=None)
Evenly round to the given number of decimals.
Parameters:
a : array_like
Input data.
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.
out : ndarray, optional
Alternative output array in which to place the result. It must have the same shape as the expected output, but the type of the output values will be cast if necessary. See doc.ufuncs (Section “Output arguments”) for details.
Returns:
rounded_array : ndarray
An array of the same type as a, containing the rounded values. Unless out was specified, a new array is created. A reference to the result is returned.
The real and imaginary parts of complex numbers are rounded separately. The result of rounding a float is a float.
See also
ndarray.round
equivalent method
ceil, fix, floor, rint, trunc
>>> np.around([0.37, 1.64]) array([ 0., 2.]) >>> np.around([0.37, 1.64], decimals=1) array([ 0.4, 1.6]) >>> np.around([.5, 1.5, 2.5, 3.5, 4.5]) # rounds to nearest even value array([ 0., 2., 2., 4., 4.]) >>> np.around([1,2,3,11], decimals=1) # ndarray of ints is returned array([ 1, 2, 3, 11]) >>> np.around([1,2,3,11], decimals=-1) array([ 0, 0, 0, 10])