insert_dims#
- sionna.phy.utils.insert_dims(tensor: torch.Tensor, num_dims: int, axis: int = -1) torch.Tensor[source]#
Adds multiple length-one dimensions to a tensor.
This operation is an extension to PyTorch’s
unsqueezefunction. It insertsnum_dimsdimensions of length one starting from the dimensionaxisof atensor. The dimension index follows Python indexing rules, i.e., zero-based, where a negative index is counted backward from the end.- Parameters:
tensor (torch.Tensor) – Input tensor
num_dims (int) – Number of dimensions to add
axis (int) – Dimension index at which to expand the shape of
tensor. Given atensorof D dimensions,axismust be within the range [-(D+1), D] (inclusive).
- Outputs:
tensor – A tensor with the same data as
tensor, withnum_dimsadditional dimensions inserted at the index specified byaxis
Examples
import torch from sionna.phy.utils import insert_dims x = torch.ones([3, 4]) print(x.shape) # torch.Size([3, 4]) y = insert_dims(x, num_dims=2, axis=-1) print(y.shape) # torch.Size([3, 4, 1, 1])