pytorch .item()作用
Use torch.Tensor.item()
to get a Python number from a tensor containing a single value.
.item()
方法返回张量元素的值。
>>> import torch >>> x = torch.tensor([[1]]) >>> x tensor([[1]]) >>> x.item() 1 >>> x = torch.tensor(2.5) >>> x tensor(2.5000) >>> x.item() 2.5
原文:https://www.cnblogs.com/Overture/p/14665433.html