expand_dims¶
dragon.vm.tensorflow.
expand_dims
(
input,
axis,
name=None
)[source]¶Expand the dimensions of input with size 1.
axis
could be negative orNone
:x = tf.ones((2, 3, 4, 5)) # axis is the size-1 position in output print(tf.expand_dims(x, axis=0).shape) # (2, 3, 4, 5) -> (1, 2, 3, 4, 5) print(tf.expand_dims(x, axis=1).shape) # (2, 3, 4, 5) -> (2, 1, 3, 4, 5) # A negative axis is the last-k axis print(tf.expand_dims(x, axis=4).shape) # (2, 3, 4, 5) -> (2, 3, 4, 5, 1) print(tf.expand_dims(x, axis=-1).shape) # Equivalent # Also, axis could be a sequence of integers print(tf.expand_dims(x, axis=[-1, -3]).shape) # (2, 3, 4, 5) -> (2, 3, 4, 1, 5, 1)
- Parameters:
- input (dragon.Tensor) – The input tensor.
- axis (Union[int, Sequence[int]]) – The axis to insert the new dimension(s).
- name (str, optional) – The operation name.
- Returns:
dragon.Tensor – The output tensor.