【学习笔记】PyTorch中.item()用法

官方文档解释.item()用法是:一个元素张量可以用x.item()得到元素值

Use torch.Tensor.item() to get a Python number from a tensor containing a single value.

 item是得到一个元素张量里面的元素值

如:

查看x的类型:

tensor类型在做运算的时候会构建计算图,因此需要转变为item()

猜你喜欢

转载自blog.csdn.net/weixin_45223645/article/details/115637394