【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是整除,得到的是整数。
推荐阅读
-
【pytorch】RuntimeError: Integer division of tensors using div or / is no longer supported
-
【pytorch】RuntimeError: Integer division of tensors using div or / is no longer supported【解决】
-
【pytorch】【解决】RuntimeError: Integer division of tensors using div or / is no longer supported
-
RuntimeError: Integer division of tensors using div or / is no longer supported, and in a future rel
-
RuntimeError: Integer division of tensors using div or / is no longer supported, and in a future rel