NumPy Tutorial NumPy Statistics NumPy References

NumPy - rint() function



The NumPy rint() function is used to round elements of the array to the nearest integer. The syntax for using this function is given below:

Syntax

numpy.rint(x, out=None)

Parameters

x Required. Specify the input array.
out Optional. Specify a location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or None, a freshly-allocated array is returned.

Return Value

Returns an array containing the rounded values if out=None. If an output array is specified, a reference to out is returned.

Example:

The example below shows the usage of rint() function.

import numpy as np
Arr = np.array([[3.4,5.6],[-7.8,-15.4]])

print("Arr is:")
print(Arr )

#rounds the values to nearest integer
print("\nRounded Array (nearest integer) is:")
print(np.rint(Arr))

The output of the above code will be:

Arr is:
[[  3.4   5.6]
 [ -7.8 -15.4]]

Rounded Array (nearest integer) is:
[[  3.   6.]
 [ -8. -15.]]

❮ NumPy - Functions