search
Search
Unlock 100+ guides
search toc
close
Cancel
Post
account_circle
Profile
exit_to_app
Sign out
What does this mean?
Why is this true?
Give me some examples!
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

NumPy | around method

schedule Aug 12, 2023
Last updated
local_offer
PythonNumPy
Tags
mode_heat
Master the mathematics behind data science with 100+ top-tier guides
Start your free 7-days trial now!

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]) ```
Edited by 0 others
thumb_up
thumb_down
Comment
Citation
Ask a question or leave a feedback...
thumb_up
0
thumb_down
0
chat_bubble_outline
0
settings
Enjoy our search
Hit / to insta-search docs and recipes!