numpy
  1. numpy-rint

rint() - ( NumPy Functions )

Heading h2

Syntax

numpy.rint(x, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj])

Example

import numpy as np

x = np.array([1.3, 2.7, 3.2, 4.8, 5.1])
rinted = np.rint(x)
print(rinted)

Output

[1. 3. 3. 5. 5.]

Explanation

The rint() function in NumPy returns the rounded value of the input to the nearest integer.

The x parameter is the input array. The out parameter is the optional output array where the result will be stored. The where parameter is an optional boolean array indicating where the function should be applied. The casting parameter is used to specify the typecasting rules. The dtype parameter is used to specify the data type for the result.

Use

The rint() function can be used to round an array of numbers to the nearest integer. This can be useful in certain numerical applications, such as signal processing or image processing.

Important Points

  • The rint() function rounds the input array to the nearest integer
  • The dtype parameter can be used to specify the data type for the result
  • The out parameter is used to specify an optional output array where the result will be stored

Summary

In conclusion, the rint() function in NumPy can be used to round an array of numbers to the nearest integer. It is a useful function in many numerical applications that require rounding of numbers. The function takes several optional parameters that can be used to specify the typecasting rules and data type of the result. It is a simple and effective function that can be used in a wide variety of applications.

Published on: