mindspore.ops.flatten
- mindspore.ops.flatten(input, order='C', *, start_dim=1, end_dim=- 1)[source]
Flatten a tensor along dimensions from start_dim to start_dim.
- Parameters
- Keyword Arguments
- Returns
Tensor. If no dimensions are flattened, returns the original input, otherwise return the flattened Tensor. If input is a 0-dimensional Tensor, a 1-dimensional Tensor will be returned.
- Raises
TypeError – If input is not a Tensor.
TypeError – If order is not string type.
ValueError – If order is string type, but not ‘C’ or ‘F’.
TypeError – If start_dim or end_dim is not int.
ValueError – If start_dim is greater than end_dim after canonicalized.
ValueError – If start_dim or end_dim is not in range of [-input.dim, input.dim-1].
- 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) >>> output = ops.flatten(input_x) >>> print(output.shape) (1, 24)