numpy.round() optionally accepts a specified number of digits to round to. However, torch.round does not, and while it seems like PyTorch will conform to NumPy eventually, what are people's current solutions?
I just want a function like torch.round(3.22, decimals=1) that returns 3.2.
CodePudding user response:
You can define your own rounding function by
def round(x, decimals=0):
b = 10**decimals
return torch.round(x*b)/b
