官方文档解释.item()用法是:一个元素张量可以用x.item()得到元素值
Use
torch.Tensor.item()
to get a Python number from a tensor containing a single value.
item是得到一个元素张量里面的元素值
如:
查看x的类型:
tensor类型在做运算的时候会构建计算图,因此需要转变为item()
官方文档解释.item()用法是:一个元素张量可以用x.item()得到元素值
Use
torch.Tensor.item()
to get a Python number from a tensor containing a single value.
item是得到一个元素张量里面的元素值
如:
查看x的类型:
tensor类型在做运算的时候会构建计算图,因此需要转变为item()