squeeze

dragon.squeeze(
  inputs,
  axis=None,
  copy=True,
  **kwargs
)[source]

Remove the dimensions of input with size 1.

axis could be negative or None:

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

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

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

# Also, axis could be a sequence of integers
print(dragon.squeeze(x, axis=[0, 3]).shape)  # (1, 2, 2, 1) -> (2, 2)
Parameters:
  • inputs (dragon.Tensor) The input tensor.
  • axis (Union[int, Sequence[int]], optional) The axis to remove.
  • copy (bool, optional, default=True) Return a new tensor or call in-place.
Returns:

dragon.Tensor The output tensor.