Python| numpy matrix.flatten()
在Numpy matrix.flatten()
方法的帮助下,我们能够对给定的矩阵进行flatten
并将输出作为一维矩阵提供。
Syntax : matrix.flatten()
Return : Return flatten 1-D matrix
示例 #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]]