Python | Numpy matrix.resize()
With the help of Numpy matrix.resize() method, we are able to resize the shape of the given matrix. Remember all elements should be covered after resizing the given matrix.
Syntax :
matrix.resize(shape)Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course
Return: new resized matrix
Example #1 :
In the given example we are able to resize the given matrix by using matrix.resize() method.
# import the important module in pythonimport numpy as np # make matrix with numpygfg = np.matrix('[64, 1; 12, 3]') # applying matrix.resize() methodgeeks = gfg.resize((1, 4)) print(geeks) |
[[64 1 12 3]]
Example #2 :
# import the important module in pythonimport numpy as np # make a matrix with numpygfg = np.matrix('[1, 2; 4, 5; 7, 8]') # applying matrix.resize() methodgeeks = gfg.resize((2, 3)) print(geeks) |
[[1 2 4] [5 7 8]]


