torchcvnn.transforms.Unsqueeze

class torchcvnn.transforms.Unsqueeze(dim: int)[source]

Add a singleton dimension to the input array/tensor.

This transform inserts a new axis at the specified position, increasing the dimensionality of the input by one.

Parameters:

dim (int) – Position where new axis should be inserted.

Returns:

Input with new singleton dimension added.

Shape will be same as input but with a 1 inserted at position dim.

Return type:

np.ndarray | torch.Tensor

Example

>>> transform = Unsqueeze(dim=0)
>>> x = torch.randn(3,4)  # Shape (3,4)
>>> y = transform(x)      # Shape (1,3,4)
__init__(dim: int) None[source]

Methods

__init__(dim)