PyTorch torch.round Function
Pytorch torch Reference Manual
torch.roundIt is a function in PyTorch for element-wise rounding.
Function Definition
torch.round(input, decimals, out)
Usage Example
Example
import torch
x = torch.tensor([0.1, 0.5, 0.9, 1.2, 1.5])
print(torch.round(x))
# Specify the number of decimal places
y = torch.tensor([1.234, 5.678])
print(torch.round(y, decimals=2))
x = torch.tensor([0.1, 0.5, 0.9, 1.2, 1.5])
print(torch.round(x))
# Specify the number of decimal places
y = torch.tensor([1.234, 5.678])
print(torch.round(y, decimals=2))
The output result is:
tensor([0., 0., 1., 1., 2.]) tensor([1.2300, 5.6800])
Other Extensions