Facebook Page Twitter Page LinkedIn Page
× NumPy Tutorial NumPy Resources

The NumPy around() function is used to return the value rounded to the desired precision. The syntax for using this function is given below:


numpy.around(a, decimals=0, out=None)


a Required. Specify the input array [array_like].
decimals Optional. Specify the decimal places to which the number is to be rounded. The default is 0. If negative integer is provided, then the integer is rounded to position to the left of the decimal point.
out Optional. Specify output array in which to place the result. It must have the same shape as the expected output.

Return Value

Returns an array of the same type as a, containing the rounded values. Unless it is specified, a new array is created. A reference to the result is returned.


The below example shows how to use the numpy.around() function.

import numpy as np

Arr = np.array([0.655, 6.125, 52.978, 167.23])

#rounding the array to 2 decimal points
print("Rounded to 2 decimal places:")
print(np.around(Arr, 2))

#rounding the array to 0 decimal points
print("\nRounded to 0 decimal places:")

#rounding the array to -1 decimal points
print("\nRounded to -1 decimal places:")
print(np.around(Arr, -1))

The output of the above code will be:

Rounded to 2 decimal places:
[   0.66    6.12   52.98  167.23]

Rounded to 0 decimal places:
[   1.    6.   53.  167.]

Rounded to -1 decimal places:
[   0.   10.   50.  170.]

❮ NumPy - Functions