在Python编程中,我使用Pytorch遇到了这个错误
4和> 5正在打印x的类型以检查张量的类型,但返回不同的结果
为什么会这样?My Code of Execution
x = x.type(torch.int64)
print(x.type())
type(X)
答案 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