Python Numpy matrix.reshape()
在Numpy matrix.reshape()方法的帮助下,我们能够重塑给定矩阵的形状。记住,在重塑给定的矩阵后,所有元素都应该被覆盖。
语法: matrix.reshape(shape)
返回:新的重新处理过的矩阵
例子#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]]