mindspore.ops.Flatten

class mindspore.ops.Flatten[source]

Flattens a tensor without changing its batch size on the 0-th axis.

Refer to mindspore.ops.flatten() for more details.

Inputs:
  • input_x (Tensor) - Tensor of shape \((N, \ldots)\) to be flattened, where \(N\) is batch size.

Outputs:

Tensor, the shape of the output tensor is \((N, X)\), where \(X\) is the product of the remaining dimension.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>> import numpy as np
>>> from mindspore import Tensor, ops
>>> input_x = Tensor(np.ones(shape=[1, 2, 3, 4]), mindspore.float32)
>>> flatten = ops.Flatten()
>>> output = flatten(input_x)
>>> print(output.shape)
(1, 24)