借助matrix.swapaxes()
方法,我們可以使用相同的方法交換軸矩陣。
用法:matrix.swapaxes()
返回: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]]
相關用法
- Python Numpy numpy.ndarray.__divmod__()用法及代碼示例
- Python Numpy numpy.ndarray.__invert__()用法及代碼示例
- Python Numpy numpy.ndarray.__mod__()用法及代碼示例
- Python Numpy numpy.ndarray.__floordiv__()用法及代碼示例
- Python Numpy numpy.ndarray.__add__()用法及代碼示例
- Python Numpy numpy.ndarray.__sub__()用法及代碼示例
- Python Numpy numpy.ndarray.__mul__()用法及代碼示例
- Python Numpy numpy.ndarray.__pow__()用法及代碼示例
- Python Numpy numpy.ndarray.__or__()用法及代碼示例
- Python Numpy numpy.ndarray.__and__()用法及代碼示例
- Python Numpy numpy.ndarray.__xor__()用法及代碼示例
- Python Numpy numpy.ndarray.__iadd__()用法及代碼示例
- Python Numpy numpy.ndarray.__isub__()用法及代碼示例
- Python Numpy numpy.ndarray.__imul__()用法及代碼示例
- Python Numpy numpy.ndarray.__ne__()用法及代碼示例
注:本文由純淨天空篩選整理自Jitender_1998大神的英文原創作品 Python | Numpy matrix.swapaxes()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。