mindspore.mint.round

View Source On Gitee
mindspore.mint.round(input, *, decimals=0)[source]

Round elements of input to the nearest integer.

outiinputi

Note

The input data types supported by the Ascend platform include bfloat16 (Atlas training series products are not supported), float16, float32, float64, int32, and int64.

Parameters

input (Tensor) – The input tensor.

Keyword Arguments

decimals (int, optional) – Number of decimal places to round. If decimals is negative, it specifies the number of positions to the left of the decimal point. Default 0 .

Returns

Tensor

Supported Platforms:

Ascend

Examples

>>> import mindspore
>>> output = mindspore.mint.round(mindspore.tensor([4.7, -2.3, 9.1, -7.7]))
>>> print(output)
[ 5. -2.  9. -8.]
>>> # Values equidistant from two integers are rounded towards the
>>> # the nearest even value (zero is treated as even)
>>> output = mindspore.mint.round(mindspore.tensor([-0.5, 0.5, 1.5, 2.5]))
>>> print(output)
[0. 0.  2.  2.]
>>> # A positive decimals argument rounds to the to that decimal place
>>> output = mindspore.mint.round(mindspore.tensor([0.1234567]), decimals=3)
>>> print(output)
[0.123]
>>> # A negative decimals argument rounds to the left of the decimal
>>> output = mindspore.mint.round(mindspore.tensor([1200.1234567]), decimals=-3)
>>> print(output)
[1000.]