PyTorch 相当于 Numpy Round?

PyTorch equivalent of Numpy Round?

numpy.round() 可选择接受要舍入到的指定位数。然而,torch.round没有,而it seems like PyTorch will conform to NumPy eventually,人们目前的解决方案是什么?

我只想要 torch.round(3.22, decimals=1) 这样的函数 returns 3.2

您可以通过

定义自己的舍入函数
def round(x, decimals=0):
    b = 10**decimals
    return torch.round(x*b)/b