📜  Python| numpy matrix.resize()

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

Python| numpy matrix.resize()

借助Numpy matrix.resize()方法,我们能够调整给定矩阵的形状。请记住,在调整给定矩阵的大小后应覆盖所有元素。

示例 #1:
在给定的示例中,我们可以使用matrix.resize()方法调整给定矩阵的大小。

# import the important module in python
import numpy as np
           
# make matrix with numpy
gfg = np.matrix('[64, 1; 12, 3]')
           
# applying matrix.resize() method
geeks = gfg.resize((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.resize() method
geeks = gfg.resize((2, 3))
     
print(geeks)
输出:
[[1 2 4]
 [5 7 8]]