Shortcuts

expand_as_right

class tensordict.utils.expand_as_right(tensor: torch.Tensor | TensorDictBase, dest: torch.Tensor | TensorDictBase)

Expand a tensor on the right to match another tensor shape.

Parameters:
  • tensor – tensor to be expanded

  • dest – tensor providing the target shape

Returns:

a tensor with shape matching the dest input tensor shape.

Examples

>>> tensor = torch.zeros(3,4)
>>> dest = torch.zeros(3,4,5)
>>> print(expand_as_right(tensor, dest).shape)
torch.Size([3,4,5])

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources