expand_dims¶
dragon.
expand_dims
(
inputs,
axis,
copy=True,
**kwargs
)[source]¶Expand the dimensions of input with size 1.
axis
could be negative orNone
:x = dragon.ones((2, 3, 4, 5)) # axis is 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.
- copy (bool, optional, default=True) – Return a new tensor or call in-place.
- Returns:
dragon.Tensor – The output tensor.