torch.Tensor.tolist
- Tensor.tolist() → 列表或数字
返回张量作为(嵌套)列表。对于标量,返回标准的 Python 数字,就像在
item()
中一样。如果需要,张量会自动移动到 CPU 上。这个操作不可微分。
示例:
>>> a = torch.randn(2, 2) >>> a.tolist() [[0.012766935862600803, 0.5415473580360413], [-0.08909505605697632, 0.7729271650314331]] >>> a[0,0].tolist() 0.012766935862600803