通话单返回不同的结果

时间:2020-06-01 06:08:37

标签: python-3.x types pytorch

在Python编程中,我使用Pytorch遇到了这个错误

4和> 5正在打印x的类型以检查张量的类型,但返回不同的结果

为什么会这样?My Code of Execution

x = x.type(torch.int64)
print(x.type())
type(X)

1 个答案:

答案 0 :(得分:0)

这是自0.4版以来的PyTorch known behavior,尽管维护者没有提供理由。

还要注意,张量的type()不再反映数据类型。改用isinstance()x.type()

x = torch.DoubleTensor([1, 1, 1])
print(type(x))  # was torch.DoubleTensor
# "<class 'torch.Tensor'>"
print(x.type())  # OK: 'torch.DoubleTensor'
# 'torch.DoubleTensor'
print(isinstance(x, torch.DoubleTensor))  # OK: True
# True
相关问题