mindspore.Tensor.flatten
- Tensor.flatten(order='C')[source]
Return a copy of the tensor collapsed into one dimension.
- Parameters
order (str, optional) – Can choose between ‘C’ and ‘F’. ‘C’ means to flatten in row-major (C-style) order. ‘F’ means to flatten in column-major (Fortran-style) order. Default: ‘C’.
- Returns
Tensor, has the same data type as input.
- Raises
TypeError – If order is not string type.
ValueError – If order is string type, but not ‘C’ or ‘F’.
See also
mindspore.Tensor.reshape()
: Give a new shape to a tensor without changing its data.mindspore.Tensor.ravel()
: Return a contiguous flattened tensor.- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import numpy as np >>> from mindspore import Tensor >>> x = Tensor(np.ones((2,3,4), dtype=np.float32)) >>> output = x.flatten() >>> print(output.shape) (24,)