expand_dims

dragon.expand_dims(
  inputs,
  axis,
  **kwargs
)[source]

Expand the dimensions of input with size 1.

The argument axis could be negative or None:

x = dragon.ones((2, 3, 4, 5))

# ``axis`` determines the size-1 position in output
print(dragon.expand_dims(x, axis=0).shape)  # (2, 3, 4, 5) -> (1, 2, 3, 4, 5)
print(dragon.expand_dims(x, axis=1).shape)  # (2, 3, 4, 5) -> (2, 1, 3, 4, 5)

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

# Also, ``axis`` could be a sequence of integers
print(dragon.expand_dims(x, axis=[-1, -3]).shape)  # (2, 3, 4, 5) -> (2, 3, 4, 1, 5, 1)
Parameters:
  • inputs (dragon.Tensor) – The input tensor.
  • axis (Union[int, Sequence[int]]) – The axis to insert the new dimension(s).
Returns:

dragon.Tensor – The output tensor.