Python 3.x Call语句返回不同的结果

Python 3.x Call语句返回不同的结果,python-3.x,types,pytorch,Python 3.x,Types,Pytorch,在Python编程中,我使用Pytorch得到了这个错误 4和>5正在打印x的类型以检查张量的类型,但返回不同的结果 为什么会发生这种情况 这是PyTorch自0.4版以来的一个版本,尽管维护人员没有提供理由 还要注意,张量的type()不再反映数据类型。改用isinstance()或x.type() x = torch.DoubleTensor([1, 1, 1]) print(type(x)) # was torch.DoubleTensor # "<class 'torch.Ten

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

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

为什么会发生这种情况

这是PyTorch自0.4版以来的一个版本,尽管维护人员没有提供理由

还要注意,张量的
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
x=torch.DoubleTensor([1,1,1])
print(type(x))#是torch.DoubleTensor
# ""
打印(x.type())#确定:'torch.DoubleTensor'
#“火炬,双张量”
打印(isinstance(x,torch.DoubleTensor))#确定:真
#真的
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