numpy.matrix.flattenΒΆ
-
matrix.
flatten
(order='C')[source]ΒΆ Return a flattened copy of the matrix.
All N elements of the matrix are placed into a single row.
Parameters: order : {βCβ, βFβ, βAβ, βKβ}, optional
βCβ means to flatten in row-major (C-style) order. βFβ means to flatten in column-major (Fortran-style) order. βAβ means to flatten in column-major order if m is Fortran contiguous in memory, row-major order otherwise. βKβ means to flatten m in the order the elements occur in memory. The default is βCβ.
Returns: y : matrix
A copy of the matrix, flattened to a (1, N) matrix where N is the number of elements in the original matrix.
Examples
>>> m = np.matrix([[1,2], [3,4]]) >>> m.flatten() matrix([[1, 2, 3, 4]]) >>> m.flatten('F') matrix([[1, 3, 2, 4]])