Python| numpy matrix.swapaxes()
在matrix.swapaxes()
方法的帮助下,我们可以使用相同的方法将轴交换为矩阵。
Syntax : matrix.swapaxes()
Return : Return matrix having interchanged axes
示例 #1:
在此示例中,我们可以使用matrix.swapaxes()
方法交换矩阵的轴。
# import the important module in python
import numpy as np
# make matrix with numpy
gfg = np.matrix('[4, 1; 12, 3]')
# applying matrix.swapaxes() method
geek = gfg.swapaxes(0, 1)
print(geek)
输出:
[[ 4 12]
[ 1 3]]
示例 #2:
# import the important module in python
import numpy as np
# make matrix with numpy
gfg = np.matrix('[4, 1, 9; 12, 3, 1; 4, 5, 6]')
# applying matrix.swapaxes() method
geek = gfg.swapaxes(1, 1)
print(geek)
输出:
[[ 4 1 9]
[12 3 1]
[ 4 5 6]]