mindspore.mint.round
- mindspore.mint.round(input, *, decimals=0)[源代码]
对输入数据四舍五入到最接近的整数。
说明
Ascend平台支持的输入数据类型包括bfloat16(Atlas训练系列产品不支持)、float16、float32、float64、int32、int64。
- 参数:
input (Tensor) - 输入tensor。
- 关键字参数:
decimals (int, 可选) - 要舍入到的小数位数。如果为负数,则指定小数点左侧的位数。默认
0
。
- 返回:
Tensor
- 支持平台:
Ascend
样例:
>>> 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.]