Written and maintained by CASRAI Editorial Board
Last updated
numpy.round (also written np.round) rounds each element of an array to a chosen number of decimal places. It is a different rule from the one most people learn at school: values exactly halfway between two candidates go to the nearest even value, so np.round(2.5) returns 2.0, not 3.0. This guide covers the syntax, the half-to-even rule, why results can differ from Python’s built-in round, and a NumPy 2.0 change that breaks many older tutorials. The NumPy 2.5 manual is the reference for the signature and behaviour below.
What it is used for in research
Researchers use np.round when a computed array has to be reduced to a reporting precision, for example effect sizes to two decimals, p-values to three, or large counts to the nearest ten. The function returns a new array, so the original data stays at full precision unless you overwrite it. The practical rule for research reporting is to round for display and keep the unrounded values for any further calculation, because rounding intermediate results compounds error.
Install or access
NumPy is installed from the official project instructions at numpy.org/install. The page recommends starting with an environment-based method using conda or pip.
- pip:
pip install numpy - conda:
conda create -n my-env, thenconda activate my-env, thenconda install numpy - Virtual environment:
python -m venv my-env, thensource my-env/bin/activate(macOS and Linux) ormy-env\Scripts\activate(Windows)
Once installed, import numpy as np gives you np.round. For an introduction to the array type it operates on, see working with NumPy arrays.
Step-by-step: round an array
The signature is numpy.round(a, decimals=0, out=None). The argument a is any array_like, decimals is an integer (default 0), and out is an optional output array of the same shape.
- Import NumPy:
import numpy as np - Round to whole numbers with the default:
np.round([0.37, 1.64])returnsarray([0., 2.]). The result is still a float array. - Round to a number of decimal places by setting
decimals:np.round([0.37, 1.64], decimals=1)returnsarray([0.4, 1.6]). - Round to the left of the decimal point with a negative
decimals, which the manual defines as the number of positions to the left of the decimal point:np.round([1, 2, 3, 11], decimals=-1)returnsarray([ 0, 0, 0, 10]). - Call it as a method if you prefer:
a.round(decimals=2)on anndarrayis the equivalent form, and the method’s own page refers back tonumpy.aroundfor full documentation.
Why 2.5 rounds to 2.0
For values exactly halfway between two rounded decimal values, NumPy rounds to the nearest even value. The manual states that 1.5 and 2.5 both round to 2.0, and that -0.5 and 0.5 both round to 0.0. The documented example is np.round([.5, 1.5, 2.5, 3.5, 4.5]), which returns array([0., 2., 2., 4., 4.]).
Python’s built-in round follows the same convention: its documentation says ties go toward the even choice, so round(0.5) and round(-0.5) are 0 and round(1.5) is 2. If your reporting standard requires half-up rounding, neither function does that out of the box, so write the rule explicitly and test it on your own data rather than assuming the default matches.
Output and how to read it
The function returns an array of the same type as the input and a new array unless you pass out. What that means in practice:
| Input | Call | Result |
|---|---|---|
| Float values | np.round([0.37, 1.64]) |
Floats: array([0., 2.]) |
Integer values, positive decimals |
np.round([1, 2, 3, 11], decimals=1) |
Unchanged integers: array([ 1, 2, 3, 11]) |
Integer values, negative decimals |
np.round([1, 2, 3, 11], decimals=-1) |
array([ 0, 0, 0, 10]) |
| Complex values | np.round(z) |
Real and imaginary parts are rounded separately |
When you supply out, it must be an ndarray of the same shape as the expected output, and values are cast to its type if necessary. Rounding a float gives a float, so use .astype(int) afterwards if you need integers.
np.round vs np.around vs ndarray.round vs built-in round
All three NumPy forms do the same job: numpy.around is an alias, and ndarray.round is the equivalent method. The one that behaves differently is Python’s built-in, and the difference is visible on real values. In the NumPy manual, np.round(16.055, 2) returns 16.06 while round(16.055, 2) returns 16.05, because 16.055 is stored as 16.0549999999999997 and the built-in is the more accurate of the two for 64-bit floats, though slower.
The reason is how NumPy rounds to positive decimals. The manual describes it as equivalent to np.true_divide(np.rint(a * 10**decimals), 10**decimals): scale up, round to the nearest integer, scale back. That scaling step can introduce error. The manual’s example is np.round(56294995342131.5, 3), which gives 56294995342131.51, while np.format_float_positional(56294995342131.5, precision=3) gives '56294995342131.5'. Python’s own documentation makes the related point that round(2.675, 2) gives 2.67 instead of 2.68, and that this is not a bug but a consequence of most decimal fractions not being exactly representable as floats.
For research reporting this has one consequence: a rounded value is a display value. If a printed number must match a decimal string exactly, format the string rather than relying on a rounded float.
Troubleshooting
AttributeError: module ‘numpy’ has no attribute ’round_’
The NumPy 2.0 release notes list np.round_ among the removed names: “np.round_ has been removed. Use np.round instead.” Many older tutorials and scripts still call np.round_ and fail on NumPy 2.x. Replace it with np.round, which takes the same arguments.
2.5 became 2.0 and 3.5 became 4.0
This is the half-to-even rule described above, not a bug.
A rounded value is off in the last digit
See the scale-then-round explanation above. Use np.format_float_positional for display, or the built-in round for single 64-bit floats.
Integers did not change
For integer arrays a positive decimals has nothing to round. Use a negative value to round to tens, hundreds and so on.
Free alternatives
| Function | What it is |
|---|---|
numpy.around |
Alias of numpy.round |
ndarray.round |
Method form: a.round(decimals=0, out=None) |
Built-in round(number, ndigits=None) |
Python standard library; ties go to the even choice; returns an int if ndigits is omitted |
numpy.format_float_positional |
Produces a formatted string with a given precision, for display rather than computation |
Other array operations that commonly sit next to rounding in an analysis are clipping values to bounds, taking logarithms and generating evenly spaced values.
FAQ
Does np.round round half up?
No. Exactly halfway values go to the nearest even value, so 0.5 and 2.5 round to 0.0 and 2.0.
What is the difference between np.round and np.around?
None in behaviour: numpy.around is an alias of numpy.round.
How do I round to the nearest ten or hundred?
Pass a negative decimals. With decimals=-1, 11 becomes 10.
Why does np.round_ fail?
It was removed in NumPy 2.0. Use np.round.
Does np.round change my original array?
No. It returns a new array unless you pass out.
Sources
Checked against the official documentation on 2026-10-29.
- NumPy Manual, numpy.round: https://numpy.org/doc/stable/reference/generated/numpy.round.html (checked 2026-10-29)
- NumPy Manual, numpy.ndarray.round: https://numpy.org/doc/stable/reference/generated/numpy.ndarray.round.html (checked 2026-10-29)
- NumPy 2.0.0 Release Notes: https://numpy.org/doc/stable/release/2.0.0-notes.html (checked 2026-10-29)
- Installing NumPy: https://numpy.org/install/ (checked 2026-10-29)
- Python documentation, built-in round(): https://docs.python.org/3/library/functions.html#round (checked 2026-10-29)







