torch.Tensor.expand — PyTorch 2.7 documentation
Tensor can be also expanded to a larger number of dimensions, and the new ones will be appended at the front. For the new dimensions, the size cannot be set to -1. Expanding a tensor does not allocate new memory, but only creates a new view on the existing tensor where a dimension of size one is expanded to a larger size by setting the stride to 0. Any dimension of size 1 can be expanded to an arbitrary value without allocating new memory. *sizes (torch.Size or int...) – the desired expanded size WARNING More than one element of an expanded tensor may refer to a single memory location. As a result, in-place operations (especially ones that are vectorized) may result in incorrect behavior. If you need to write to the tensors, please clone them first. Example: © Copyright PyTorch Contributors. Access comprehensive developer documentation for PyTorch Get in-depth tutorials for beginners and advanced developers Find development resources and get your questions answered © Copyright The Linu
Rate this Page ★ ★ ★ ★ ★ Tensor.expand(*size) → Tensor# Returns a new view of the self tensor with singleton dimensions expanded to a larger size. Passing -1 as the size for a dimension means not changing the size of that dimension. Tensor can be also expanded to a larger number of dimensions, and the new ones will be appended at the front. For the new dimensions, the size cannot be set to -1. Expanding a tensor does not allocate new memory, but only creates a new view on the existing tensor where a dimension of size one is expanded to a larger size by setting the stride to 0. Any…
related reading
- torch.stackdocs.pytorch.org
- torch.reshape — PyTorch 2.12 documentationdocs.pytorch.org
- torch.Tensor — PyTorch 2.12 documentationdocs.pytorch.org
- Tensor Considered Harmfulnlp.seas.harvard.edu
- torch.stack — PyTorch 2.12 documentationdocs.pytorch.org
- torch.empty — PyTorch 2.12 documentationdocs.pytorch.org
- torch.unravel_indexdocs.pytorch.org
- PyTorch internals : ezyang's blogblog.ezyang.com
- Tensors — PyTorch Tutorials 2.12.0+cu130 documentationpytorch.org
- Taking PyTorch for Granted | whnrehiew.github.io
- Making Deep Learning go Brrrr From First Principleshorace.io
- Tensors — PyTorch Tutorials 2.13.0+cu130 documentationdocs.pytorch.org