📜  Python| numpy matrix.flatten()

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

Python| numpy matrix.flatten()

Numpy matrix.flatten()方法的帮助下,我们能够对给定的矩阵进行flatten并将输出作为一维矩阵提供。

示例 #1:
在这个例子中,我们可以看到在matrix.flatten()方法的帮助下,我们能够展平给定的矩阵。

# import the important module in python
import numpy as np
         
# make matrix with numpy
gfg = np.matrix('[6; 2; 3]')
         
# applying matrix.flatten() method
geeks = gfg.flatten()
   
print(geeks)
输出:
[[6 2 3]]

示例 #2:

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