Python | Numpy matrix.reshape()

With the help of Numpy matrix.reshape() method, we are able to reshape the shape of the given matrix. Remember all elements should be covered after reshaping the given matrix.

Syntax : matrix.reshape(shape)

Return: new reshapped matrix



Example #1 :
In the given example we are able to reshape the given matrix by using matrix.reshape() method.

filter_none

edit
close

play_arrow

link
brightness_4
code

# import the important module in python
import numpy as np
           
# make matrix with numpy
gfg = np.matrix('[64, 1; 12, 3]')
           
# applying matrix.reshape() method
geeks = gfg.reshape((1, 4))
     
print(geeks)

chevron_right


Output:

[[64  1 12  3]]

Example #2 :

filter_none

edit
close

play_arrow

link
brightness_4
code

# import the important module in python
import numpy as np
           
# make a matrix with numpy
gfg = np.matrix('[1, 2; 4, 5; 7, 8]')
           
# applying matrix.reshape() method
geeks = gfg.reshape((2, 3))
     
print(geeks)

chevron_right


Output:

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


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.