NumPy | around method
around(~) method rounds up and down the values in the input array.
The input array.
The number of decimals to round to. Note that
decimals=1 would mean that values like
1.52 will be rounded to
1.5. On the other hand,
decimals=-1 would round values like 13 to 10 (i.e. nearest 10th).
A scalar is returned if
a is a scalar, otherwise a Numpy array is returned.
Numbers ending in 5 will be rounded down.
Numbers such as
3.45 will be rounded down to
3.4, respectively, instead of rounding up.
Rounding to the nearest integer
x = np.array([2.3,2.5,2.7])np.round(x)array([2., 2., 3.])
Rounding values to the 1st decimal place
1 as the second parameter:
x = np.array([2.3,2.5,2.7])np.around(x,1)array([2.3, 2.5, 2.7])
Rounding values to the nearest 10th
-1 as the second parameter:
x = np.array([4,12,16])np.around(x,-1)array([ 0, 10, 20])