This function returns a flattened one-dimensional array. A copy is made only if needed. The returned array will have the same type as that of the input array. The function takes one parameter.

numpy.ravel(a, order)

The constructor takes the following parameters.

Sr.No. Parameter & Description


'C': row major (default. 'F': column major 'A': flatten in column-major order, if a is Fortran contiguous in memory, row-major order otherwise 'K': flatten a in the order the elements occur in the memory


import numpy as np 
a = np.arange(8).reshape(2,4) 

print 'The original array is:' 
print a 
print '\n'  

print 'After applying ravel function:' 
print a.ravel()  
print '\n' 

print 'Applying ravel function in F-style ordering:' 
print a.ravel(order = 'F')

Its output would be as follows −

The original array is:
[[0 1 2 3]
 [4 5 6 7]]

After applying ravel function:
[0 1 2 3 4 5 6 7]

Applying ravel function in F-style ordering:
[0 4 1 5 2 6 3 7]