Shortcuts

torch.Tensor.tolist

Tensor.tolist() list or number

返回张量作为一个(嵌套的)列表。对于标量,返回一个标准的Python数字,就像使用item()一样。如果需要,张量会自动移动到CPU上。

此操作不可微分。

示例:

>>> a = torch.randn(2, 2)
>>> a.tolist()
[[0.012766935862600803, 0.5415473580360413],
 [-0.08909505605697632, 0.7729271650314331]]
>>> a[0,0].tolist()
0.012766935862600803