tolist

Documentation

class treetensor.torch.Tensor(data, *args, **kwargs)[source]
tolist()[source]

Get the dump result of tree tensor.

Example:

>>> import torch
>>> import treetensor.torch as ttorch
>>> ttorch.tensor({
>>>     'a': [[1, 2], [3, 4]],
>>>     'b': [1, 2, 3],
>>>     'c': True,
>>> }).tolist()
Object({
    'a': [[1, 2], [3, 4]],
    'b': [1, 2, 3],
    'c': True,
})

Torch Version Related

This documentation is based on torch.Tensor.tolist in torch v1.9.0+cu102. Its arguments’ arrangements depend on the version of pytorch you installed.

If some arguments listed here are not working properly, please check your pytorch’s version with the following command and find its documentation.

1
python -c 'import torch;print(torch.__version__)'

The arguments and keyword arguments supported in torch v1.9.0+cu102 is listed below.

Description From Torch v1.9.0+cu102

class torch.Tensor
tolist() → list or number

Returns the tensor as a (nested) list. For scalars, a standard Python number is returned, just like with item(). Tensors are automatically moved to the CPU first if necessary.

This operation is not differentiable.

Examples:

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