flatten

dragon.flatten(
  inputs,
  axis=0,
  num_axes=-1,
  keep_axes=None,
  **kwargs
)[source]

Flatten the input along the given axes.

Set keep_axes to flatten if shape is dynamic.

Examples:

x = dragon.Tensor(shape=[1, 2, 3, 4]).variable()
print(dragon.flatten(x, axis=1, num_axes=-1).shape)  # (1, 24)
print(dragon.flatten(x, axis=1, num_axes=2).shape)  # (1, 6, 4)
print(dragon.flatten(x, keep_axes=1))  # (24,)
Parameters:
  • inputs (dragon.Tensor) – The input tensor.
  • axis (int, optional, default=0) – The start axis to flatten, can be negative.
  • num_axes (int, optional, default=-1) – The number of axes to flatten.
  • keep_axes (int, optional) – The number of axes to keep.
Returns:

dragon.Tensor – The output tensor.