Python | Numpy matrix.resize ()



Using the Numpy matrix.resize () method, we can resize this matrix. Remember that all elements must be covered after resizing this matrix.

Syntax: matrix.resize(shape)

Return: new resized matrix

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

# import important module into python

import numpy as np

  
# make a matrix with NumPy

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

 
# using the matrix.resize () method

geeks = gfg.resize (( 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] ` )

  
# applying the matrix.resize () method

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

 

print (geeks)

Exit:

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