Python | Numpy matrix.ravel ()

Using the Numpy matrix.ravel () method, we can get a flattened matrix from a given matrix.

Syntax: matrix.ravel()

Return: Return flattened matrix from given matrix

Example # 1:
In this example, we see that we can get a flattened matrix from a given matrix using the matrix method .ravel () .

# import important module into python

import numpy as np

  
# make a matrix with NumPy

gfg = np.matrix ( `[64, 1; 12, 3 ] ` )

  
# using the matrix.ravel () method

geeks = gfg.ravel ()

 

print (geeks)

Exit:

 [[64 1 12 3]] 

Example # 2:

# import important module in python

import numpy as np

 
# make a matrix with NumPy

gfg = np.matrix ( ` [1, 2, 3; 4, 5, 6; 7, 8, -9] ` )

  
# applying the matrix.ravel () method

geeks = gfg.ravel ()

 

print (geeks)

Exit:

 [[1 2 3 4 5 6 7 8 -9]]