ravel

ravel(x)

Return a contiguous flattened array. A 1-D array, containing the elements of the input, is returned. A copy is made only if needed.

Parameters:
x : ndarray

Input array. The elements in x are read in row-major, C-style order and packed as a 1-D array.

order : C, optional

Only support row-major, C-style order.

Returns:
y : ndarray

y is an array of the same subtype as x, with shape (x.size,). Note that matrices are special cased for backward compatibility, if x is a matrix, then y is a 1-D ndarray.

Notes

This function differs from the original numpy.arange in the following aspects:
  • Only support row-major, C-style order.

Examples

It is equivalent to reshape(x, -1).

>>> x = np.array([[1, 2, 3], [4, 5, 6]])
>>> print(np.ravel(x))
[1. 2. 3. 4. 5. 6.]
>>> print(x.reshape(-1))
[1. 2. 3. 4. 5. 6.]
>>> print(np.ravel(x.T))
[1. 4. 2. 5. 3. 6.]