bundles / numpy 2.4.3 / numpy / matrixlib / defmatrix / matrix / flatten
function
numpy.matrixlib.defmatrix:matrix.flatten
Signature
def flatten(self, order = C)Summary
Return a flattened copy of the matrix.
Extended Summary
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
mis Fortran contiguous in memory, row-major order otherwise. 'K' means to flattenmin the order the elements occur in memory. The default is 'C'.
Returns
y: matrixA copy of the matrix, flattened to a
(1, N)matrix whereNis the number of elements in the original matrix.
Examples
m = np.matrix([[1,2], [3,4]]) m.flatten() m.flatten('F')✓
matrix([[1, 3, 2, 4]])
See also
- flat
A 1-D flat iterator over the matrix.
- ravel
Return a flattened array.
Aliases
numpy.matrix.flatten