item作用就是把张量tensor的元素取出来,比如一个张量x,指定索引位置后把张量类型转化为python中的一种内置类型,如tensor( 2.5)中的2.5取出来,得到2.5这个浮点数,方便进行数据类型的操作
x = torch.tensor([[1]])
print(x)
print(x.item())
x = torch.tensor(2.5)
print(x)
print(x.item())

原API文档也是这么描述的

参考链接:https://pytorch.org/docs/stable/tensors.html?highlight=item#torch.Tensor.item