欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

【pytorch】【解决】RuntimeError: Integer division of tensors using div or / is no longer supported

程序员文章站 2022-06-15 14:54:30
...
x = torch.tensor([1,2,3])
n = 10
print(x/n)

运行结果:

Traceback (most recent call last):
  File "/home/yjys/PycharmProjects/TEST/validation/test/torch_test.py", line 22, in <module>
    print(x/n)
RuntimeError: Integer division of tensors using div or / is no longer supported, and in a future release div will perform true division as in Python 3. Use true_divide or floor_divide (// in Python) instead.

上面是说,使用/进行的tensor整数除法不再支持,可以使用true_divide代替。

x = torch.tensor([1,2,3])
n = 10
print(x.true_divide(n))

#output
tensor([0.1000, 0.2000, 0.3000])

而其中的floor_divide是整除,得到的是整数。

相关标签: 错误集锦