Python | Numpy matrix.flatten ()

Using the Numpy matrix.flatten () method, we can flatten a given matrix and output it as a one-dimensional matrix.

Syntax: matrix.flatten()

Return: Return flatten 1- D matrix

Example # 1:
In this example we can see that using the matrix.flatten () method we can flatten the given matrix.

# import important module into python

import numpy as np

  
# make a matrix with NumPy

gfg = np.matrix ( `[6; 2; 3]`

 
# using the matrix.flatten () method

geeks = gfg.flatten ()

 

print (geeks)

Exit:

 [[6 2 3]] 

Example # 2:

# import important module into python

import numpy as np

 
# make a matrix with NumPy

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

  
# using the matrix.flatten () method

geeks = gfg.flatten ()

 

print (geeks)

Exit:

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