mindspore.ops.round

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

Round elements of input to the nearest integer.

\[out_i \approx input_i\]

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 GPU CPU

Examples

>>> import mindspore
>>> output = mindspore.ops.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.ops.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.ops.round(mindspore.tensor([0.1234567]), decimals=3)
>>> print(output)
[0.123]
>>> # A negative decimals argument rounds to the left of the decimal
>>> output = mindspore.ops.round(mindspore.tensor([1200.1234567]), decimals=-3)
>>> print(output)
[1000.]