📜  Python| numpy matrix.reshape()

📅  最后修改于: 2022-05-13 01:54:43.575000             🧑  作者: Mango

Python| numpy matrix.reshape()

Numpy matrix.reshape()方法的帮助下,我们能够重塑给定矩阵的形状。请记住,在重塑给定矩阵后应覆盖所有元素。

示例 #1:
在给定的示例中,我们可以使用matrix.reshape()方法重塑给定的矩阵。

# 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)
输出:
[[64  1 12  3]]

示例 #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
geeks = gfg.reshape((2, 3))
     
print(geeks)
输出:
[[1 2 4]
 [5 7 8]]