Return a flattened array.
A 1-D array, containing the elements of the input, is returned. A copy is made only if needed.
Parameters: | a : array_like
order : {‘C’,’F’}, optional
|
---|---|
Returns: | 1d_array : ndarray
|
See also
Notes
In row-major order, the row index varies the slowest, and the column index the quickest. This can be generalized to multiple dimensions, where row-major order implies that the index along the first axis varies slowest, and the index along the last quickest. The opposite holds for Fortran-, or column-major, mode.
Examples
If an array is in C-order (default), then ravel is equivalent to reshape(-1):
>>> x = np.array([[1, 2, 3], [4, 5, 6]])
>>> print x.reshape(-1)
[1 2 3 4 5 6]
>>> print np.ravel(x)
[1 2 3 4 5 6]
When flattening using Fortran-order, however, we see
>>> print np.ravel(x, order='F')
[1 4 2 5 3 6]