pytorch中.data()与.item()
1..data()
将变量(Variable)变为tensor,将requires_grad
设置为Flase
a = torch.tensor([1.0], requires_grad=True)
b = a.data
print(b, b.requires_grad)
## 输出为: tensor([1.]) False
2..item()
a = torch.tensor([1.0], requires_grad=True)
c = a.item()
print(c, type(c))
## 输出为:1.0 <class 'float'>