mrpro.utils.unsqueeze_tensors_at

mrpro.utils.unsqueeze_tensors_at(*x, dim: int, ndim: int | None = None) tuple[Tensor, ...][source]

Unsqueeze tensors at a specific dimension to the same number of dimensions.

Example

  • Tensors with shapes (1, 2, 3) and (1, 3) and dim=-2 result in tensors with shapes (1, 2, 3) and (1, 1, 3), as the maximum number of input dimensions is 3.

  • Tensors with shapes (1, 2, 3) and (1, 3) and dim=1 and ndim=4 result in tensors with shapes (1, 1, 2, 3) and (1, 1, 1, 3).

Parameters:
  • x – Tensors to unsqueeze.

  • dim (int) – Dimension to unsqueeze.

  • ndim (int | None, default: None) – Number of dimensions to unsqueeze to. If None, unsqueeze to the maximum number of dimensions of the input tensors.

Returns:

Unsqueezed tensors (views) with the same number of dimensions.