search
Search
Guest 0reps
Thanks for the thanks!
close
account_circle
Profile
exit_to_app
Sign out
search
keyboard_voice
close
Searching Tips
Search for a recipe:
"Creating a table in MySQL"
Search for an API documentation: "@append"
Search for code: "!dataframe"
Apply a tag filter: "#python"
Useful Shortcuts
/ to open search panel
Esc to close search panel
to navigate between search results
d to clear all current filters
Enter to expand content preview
Doc Search
Code Search Beta
SORRY NOTHING FOUND!
mic
Start speaking...
Voice search is only supported in Safari and Chrome.
Shrink
Navigate to
A
A
brightness_medium
share
arrow_backShare

# NumPy | around method

Programming
chevron_right
Python
chevron_right
NumPy
chevron_right
Documentation
schedule Jul 1, 2022
Last updated
local_offer PythonNumPy
Tags

Numpy's `around(~)` method rounds up and down the values in the input array.

# Parameters

1. `a` | `array_like`

The input array.

2. `decimals` | `int` | `optional`

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).

# Return value

A scalar is returned if `a` is a scalar, otherwise a Numpy array is returned.

WARNING

Numbers ending in 5 will be rounded down.

Numbers such as `2.5` and `3.45` will be rounded down to `2` and `3.4`, respectively, instead of rounding up.

# Examples

## 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

Set `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

Set `-1` as the second parameter:

``` x = np.array([4,12,16])np.around(x,-1) array([ 0, 10, 20]) ```
mail
Edited by 0 others