TensorDictBase.broadcast_to#
- TensorDictBase.broadcast_to(shape: tuple[int, ...])#
Returns the tensordict broadcast to the batch size
shape, astorch.broadcast_to()does.As for
expand(), the new shape can add leading dimensions and expand the dimensions of size 1, and-1keeps the size of a dimension. The leaves of the result are views of the original leaves, and the result has no names.Examples
>>> import torch >>> from tensordict import TensorDict >>> td = TensorDict({"a": torch.arange(3)}, batch_size=[3]) >>> print(td.broadcast_to((2, 3)).shape) torch.Size([2, 3])
Every tensordict class and every tensorclass has this method. For the other methods, see Methods by task.