Numpy rint()

This function is used to round the array elements to the nearest integer.

Syntax

snippet
numpy.rint(array)

Parameters

  1. array: Array elements whose nearest integers are to be calculated.

Return

An array containing the rounded values is returned.

Example

snippet
import numpy as np

arr = [0.23, 0.09, 1.2, 1.24, 9.99]

print("Input array:",arr)

r_arr = np.rint(arr)

print("Output array:",r_arr)

Output:

Output
Input array: [0.23, 0.09, 1.2, 1.24, 9.99] Output array: [ 0. 0. 1. 1. 10.]
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents +