Python | Numpy matrix.reshape ()

Using the Numpy matrix.reshape () method, we can change the shape of this matrix. Remember that all elements must be covered after reshaping this matrix.

Syntax: matrix.reshape(shape)

Return: new reshapped matrix

Example # 1:
In this For example, we can reshape this matrix using matrix.reshape () .

# import important module into python

import numpy as np

  
# make a matrix with NumPy

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

 
# using the matrix.reshape () method

geeks = gfg.reshape (( 1 , 4 ))

 

print (geeks)

Output:

 [[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; 4, 5; 7, 8] ' )

  
# using the matrix.reshape () method

geeks = gfg.reshape (( 2 , 3 ))

 

print (geeks)

Exit:

 [[1 2 4] [5 7 8]] 




Get Solution for free from DataCamp guru