Tuesday, September 24, 2024
Google search engine
HomeLanguagesPython | Numpy matrix.reshape()

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 the important module in python
import numpy as np
           
# make matrix with numpy
gfg = np.matrix('[64, 1; 12, 3]')
           
# applying matrix.reshape() method
Lazyroar = gfg.reshape((1, 4))
     
print(Lazyroar)


Output:

[[64  1 12  3]]

Example #2 :




# 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
Lazyroar = gfg.reshape((2, 3))
     
print(Lazyroar)


Output:

[[1 2 4]
 [5 7 8]]
Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments