Rate this Page
★ ★ ★ ★ ★

TensorDictBase.names#

property TensorDictBase.names#

The dimension names of the tensordict, one per batch dimension.

A dimension without a name is None. The names can be set at construction time using the names argument, or by assignment (td.names = [...]). The names must be unique. Shape operations and indexing keep the names of the dimensions that remain. See Batch size, shapes, and indexing.

See also refine_names() for details on how to set the names after construction.

Examples

>>> import torch
>>> from tensordict import TensorDict
>>> td = TensorDict(a=torch.zeros(3, 4), batch_size=[3, 4], names=["time", None])
>>> td.names
['time', None]
>>> td.names = ["time", "batch"]
>>> td[0].names
['batch']

Every tensordict class and every tensorclass has this method. For the other methods, see Methods by task.