squeeze¶
dragon.vm.tensorflow.
squeeze
(
input,
axis=None,
copy=True,
name=None
)[source]¶Remove the dimensions of input with size 1.
axis
could be negative orNone
:x = tf.ones((1, 2, 2, 1)) # Remove all matched dimensions if axis is None # Otherwise, only the specified axes will be removed print(tf.squeeze(x).shape) # (1, 2, 2, 1) -> (2, 2) print(tf.squeeze(x, axis=0).shape) # (1, 2, 2, 1) -> (2, 2, 1) # A negative axis is the last-k axis print(tf.squeeze(x, axis=3).shape) # (1, 2, 2, 1) -> (1, 2, 2) print(tf.squeeze(x, axis=-1).shape) # Equivalent # Also, axis could be a sequence of integers print(tf.squeeze(x, axis=[0, 3]).shape) # (1, 2, 2, 1) -> (2, 2)
- Parameters:
- input (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.
- name (str, optional) – The operation name.
- Returns:
dragon.Tensor – The output tensor.