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 reshaped matrix
Example #1 :
In the given example we are able to reshape the given matrix by using matrix.reshape()
method.
import numpy as np
gfg = np.matrix( '[64, 1; 12, 3]' )
geeks = gfg.reshape(( 1 , 4 ))
print (geeks)
|
Example #2 :
import numpy as np
gfg = np.matrix( '[1, 2; 4, 5; 7, 8]' )
geeks = gfg.reshape(( 2 , 3 ))
print (geeks)
|
Output:
[[1 2 4]
[5 7 8]]
Last Updated :
17 Feb, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...