# What are some efficient functions to round off numbers in an array?

I recently discovered a method in NumPy for rounding off all elements of an array to the nearest integer using NumPy’s `np.round()` function.

I’m curious to know if there are any other substitute and efficient methods for achieving the same. Can anyone explain with sample codes?

1 Like

Yes, there are substitute methods of rounding off elements in an array, one of them involves using the `np.around()` function of NumPy which offers you more flexibility as you can round off numbers according to your given number of decimals. Below is an example code that shows you the working of this function:

The code uses the `np.around()` function to round off the elements of array `a` to `2` decimal places, and the result is stored in a new array called `b`.

Yes, you can use the `np.floor()` method to round off the elements in a NumPy array. It will simply drop the decimal value and return only integer.

This Python code utilizes NumPy to apply the floor function to a given array, rounding down each element to the nearest integer, and then prints the resulting array.