-
.numpy()
- 官方文档:https://pytorch.org/docs/stable/tensors.html#torch.Tensor.numpy
- 功能:将张量转换为与其共享底层存储的 n 维 numpy 数组
-
.item()
- 官方文档:https://pytorch.org/docs/stable/tensors.html#torch.Tensor.cpu
- 功能:将张量的值转换为标准的 Python 数值,只有当张量仅含一个元素时才能使用它
-
.detach()
- 官方文档:https://pytorch.org/docs/stable/autograd.html#torch.Tensor.detach
- 功能:返回一个与当前 graph 分离的、不再需要梯度的新张量
-
.cuda()
- 官方文档:https://pytorch.org/docs/stable/tensors.html#torch.Tensor.cuda
- 功能:将张量拷贝到 GPU 上
-
.cpu()
- 官方文档:https://pytorch.org/docs/stable/tensors.html#torch.Tensor.cpu
- 功能:将张量拷贝到 CPU 上
PyTorch 中常见的基础型张量操作 .numpy()、.item()、.detach()、.gpu()、.cpu()
最新推荐文章于 2022-12-13 21:13:40 发布