🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.round.html
numpy.round — NumPy v2.4 Manual
Thus 1.5 and 2.5 round to 2.0, -0.5 and 0.5 round to 0.0, etc. np.round uses a fast but sometimes inexact algorithm to round floating-point datatypes.
🌐
DataCamp
datacamp.com › tutorial › python-round-up
How to Round Up a Number in Python | DataCamp
July 22, 2024 - Discover three straightforward techniques to round up numbers in Python: using math.ceil() from the math module, using the decimal module, and NumPy.
🌐
Medium
medium.com › @heyamit10 › how-to-round-numbers-to-integers-in-numpy-c43b43970c4c
How to Round Numbers to Integers in NumPy? | by Hey Amit | Medium
March 6, 2025 - Well, imagine you’re dealing with financial data, scientific measurements, or any situation where precision matters. Instead of rounding 1.746 to 2, maybe you just want to round it to one decimal place, like 1.7. ... import numpy as np arr = np.array([1.746, 2.312, 3.876, 4.543]) rounded_arr = np.round(arr, decimals=1) print(rounded_arr)
🌐
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.round.html
numpy.round — NumPy v2.1 Manual
Thus 1.5 and 2.5 round to 2.0, -0.5 and 0.5 round to 0.0, etc. np.round uses a fast but sometimes inexact algorithm to round floating-point datatypes.
🌐
Note.nkmk.me
note.nkmk.me › home › python › numpy
NumPy: Round up/down array elements (np.floor, np.trunc, np.ceil) | note.nkmk.me
January 15, 2024 - Modified: 2024-01-15 | Tags: Python, NumPy · You can use np.floor(), np.trunc(), and np.ceil() to round up and down the elements in a NumPy array (ndarray). Considering both positive and negative values, there are four main types of rounding: ...
🌐
GeeksforGeeks
geeksforgeeks.org › numpy › numpy-round_-python
numpy.round_() in Python - GeeksforGeeks
December 6, 2024 - In this example, numpy.round_() rounds each element of the array to the nearest integer.
🌐
NumPy
numpy.org › devdocs › reference › generated › numpy.round.html
numpy.round — NumPy v2.5.dev0 Manual
Thus 1.5 and 2.5 round to 2.0, -0.5 and 0.5 round to 0.0, etc. np.round uses a fast but sometimes inexact algorithm to round floating-point datatypes.
🌐
Programiz
programiz.com › python-programming › numpy › methods › round
NumPy round() (With Examples)
numpy.round(array, decimals=0, out=None) The round() function takes one argument: array - the input array whose elements are to be rounded · decimal (optional) - number up to which the elements of array is rounded · out (optional) - the output array where the result will be stored.
Find elsewhere
🌐
Note.nkmk.me
note.nkmk.me › home › python › numpy
NumPy: Round array elements (np.round, np.around, np.rint) | note.nkmk.me
January 15, 2024 - You can round the elements in a NumPy array (ndarray) to a specified number of digits using np.round(). Note that it uses bankers' rounding, which means it rounds half to even (e.g., 0.5 rounds to 0.0 ...
🌐
Codecademy
codecademy.com › docs › python:numpy › math methods › .round()
Python:NumPy | Math Methods | .round() | Codecademy
June 18, 2024 - In the NumPy library, the .round() method rounds a number or an array of numbers to a specified number of decimal places. It returns an array without commas separating the elements.
🌐
Real Python
realpython.com › python-rounding
How to Round Numbers in Python – Real Python
December 7, 2024 - To round all of the values in the data array, you can pass data as the argument to the np.round() function. You set the desired number of decimal places with the decimals keyword argument.
🌐
Vultr Docs
docs.vultr.com › python › third-party › numpy › ceil
Python Numpy ceil() - Round Up Values | Vultr Docs
November 8, 2024 - Apply ceil() to the entire array. ... import numpy as np array_values = np.array([1.7, 2.2, 3.8, 4.1]) rounded_array = np.ceil(array_values) print(rounded_array) Explain Code · In this example, all elements of the array are rounded up, transforming ...
🌐
Codecademy
codecademy.com › docs › python:numpy › ndarray › round()
Python:NumPy | ndarray | round() | Codecademy
October 29, 2025 - The round() method in NumPy rounds each element of an array to the nearest integer or to a specified number of decimal places. Values exactly halfway between two numbers are rounded to the nearest even value (also known as banker’s rounding).
🌐
Medium
medium.com › @heyamit10 › understanding-numpy-round-up-ceil-vs-round-vs-floor-f155922395b8
Understanding NumPy Round Up (ceil vs round vs floor) | by Hey Amit | Medium
April 12, 2025 - You might be wondering: “Why does this matter?” Well, in practical scenarios — like calculating prices, dealing with coordinates, or ensuring buffer limits — you often need to force numbers up instead of relying on regular rounding. Let’s see how each of these functions works in action: import numpy as np arr = np.array([1.2, 2.5, 3.8, -4.3, -5.9]) # Rounding up (ceil) rounded_up = np.ceil(arr) # Regular rounding rounded_normal = np.round(arr) # Rounding down (floor) rounded_down = np.floor(arr) print("Original:", arr) print("Ceil (Round Up):", rounded_up) # [ 2.
Top answer
1 of 2
4

The answer is almost never np.vectorize. You can, and should, do this in a fully vectorized manner. Let's say that for x >= 0, you want r = floor(x + 0.5). If you want negative numbers to round towards zero, the same formula applies for x < 0. So let's say that you always want to round away from zero. In that case, you are looking for ceil(x - 0.5) for x < 0.

To implement that for an entire array without calling np.vectorize, you can use masking:

def round_half_up(x):
    mask = (x >= 0)
    out = np.empty_like(x)
    out[mask] = np.floor(x[mask] + 0.5)
    out[~mask] = np.ceil(x[~mask] - 0.5)
    return out

Notice that you don't need to use a mask if you round all in one direction:

def round_up(x):
    return np.floor(x + 0.5)

Now if you want to make this really efficient, you can get rid of all the temp arrays. This will use the full power of ufuncs:

def round_half_up(x):
    out = x.copy()
    mask = (out >= 0)
    np.add(out, 0.5, where=mask, out=out)
    np.floor(out, where=mask, out=out)
    np.invert(mask, out=mask)
    np.subtract(out, 0.5, where=mask, out=out)
    np.ceil(out, where=mask, out=out)
    return out

And:

def round_up(x):
    out = x + 0.5
    np.floor(out, out=out)
    return out
2 of 2
1
import numpy as np
A = [ [1.0, 1.5, 3.0], [2.5, 13.4, 4.1], [13.4, 41.3, 5.1]]
A = np.array(A)

print(A)

def rounder(x):
    if (x-int(x) >= 0.5):
        return np.ceil(x)
    else:
        return np.floor(x)

rounder_vec = np.vectorize(rounder)
whole = rounder_vec(A)
print(whole)

Alternatively, you can also look at numpy.ceil, numpy.floor, numpy.trunc for other rounding styles

🌐
Vultr Docs
docs.vultr.com › python › third-party › numpy › round
Python Numpy round() - Round Decimal Numbers | Vultr Docs
November 15, 2024 - In this article, you will learn how to efficiently utilize the round() function within the NumPy library to handle decimal rounding operations.
🌐
Python Guides
pythonguides.com › python-numpy-round
Np.round() Function In Python
May 19, 2025 - Learn how to use NumPy's np.round() function to round decimal values in Python arrays with precision and control. Perfect for data science and numerical computations.
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › python numpy round() array function
Python NumPy round() Array Function - Spark By {Examples}
March 27, 2024 - In this program, the numpy.round() function is used with decimals=-1 to round the elements of the arr array to the nearest multiple of 10. Each element in the array has been rounded to the nearest multiple of 10.