squeeze

dragon.vm.torch.squeeze(
  input,
  dim=None,
  out=None
)[source]

Remove the dimensions of input with size 1.

The argument dim could be negative or None:

x = torch.ones(1, 2, 2, 1)

# Remove all matched dimensions if ``axis`` is None
# Otherwise, only the specified axes will be removed
print(torch.squeeze(x).shape)         # (1, 2, 2, 1) -> (2, 2)
print(torch.squeeze(x, dim=0).shape)  # (1, 2, 2, 1) -> (2, 2, 1)

# A negative dimension is the last-k dimension
print(torch.squeeze(x, dim=3).shape)   # (1, 2, 2, 1) -> (1, 2, 2)
print(torch.squeeze(x, dim=-1).shape)  # Equivalent

# Also, ``axis`` could be a sequence of integers
print(torch.squeeze(x, dim=[0, 3]).shape)  # (1, 2, 2, 1) -> (2, 2)
Parameters:
Returns:

dragon.vm.torch.Tensor The new tensor.