PyTorch torch.round function
PyTorch torch reference manual
torch.round is a function in PyTorch used to round elements to the nearest integer.
Function definition
torch.round(input, decimals, out)
Usage examples
Example
import
torch
x
=
torch.
tensor
(
[
0.1
,
0.5
,
0.9
,
1.2
,
1.5
]
)
(
torch.
round
(
x
)
)
Specify the number of decimal places
y
=
torch.
tensor
(
[
1.234
,
5.678
]
)
(
torch.
round
(
y
,
decimals
=
2
)
)
The output is:
tensor([0., 0., 1., 1., 2.])
tensor([1.2300, 5.6800])