SciPy

numpy.ndarray.flattenΒΆ

ndarray.flatten(order='C')ΒΆ

Return a copy of the array collapsed into one dimension.

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 a is Fortran contiguous in memory, row-major order otherwise. β€˜K’ means to flatten a in the order the elements occur in memory. The default is β€˜C’.

Returns:
y : ndarray

A copy of the input array, flattened to one dimension.

See also

ravel
Return a flattened array.
flat
A 1-D flat iterator over the array.

Examples

>>> a = np.array([[1,2], [3,4]])
>>> a.flatten()
array([1, 2, 3, 4])
>>> a.flatten('F')
array([1, 3, 2, 4])

Previous topic

numpy.ndarray.fill

Next topic

numpy.ndarray.getfield