📜  Python| numpy matrix.swapaxes()

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

Python| numpy matrix.swapaxes()

matrix.swapaxes()方法的帮助下,我们可以使用相同的方法将轴交换为矩阵。

示例 #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]]