借助Numpy matrix.byteswap()
方法,我們能夠在具有一維或多維的給定矩陣中交換元素的字節位置。它不適用於字符串或字符類型的矩陣。
用法: matrix.byteswap()
返回: 返回字節包裝矩陣
範例1:
在此示例中,我們可以借助matrix.byteswap()
方法,我們可以交換給定矩陣中元素的字節位置。
# import the important module in python
import numpy as np
# make a matrix with numpy
gfg = np.matrix('[1, 2, 3, 4]')
# applying matrix.byteswap() method
geeks = gfg.byteswap()
print(geeks)
輸出:
[[ 72057594037927936 144115188075855872 216172782113783808 288230376151711744]]
範例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.byteswap() method
geeks = gfg.byteswap()
print(geeks)
輸出:
[[ 72057594037927936 144115188075855872 216172782113783808] [288230376151711744 360287970189639680 432345564227567616] [504403158265495552 576460752303423488 648518346341351424]]
相關用法
- Python Numpy numpy.ndarray.__add__()用法及代碼示例
- Python Numpy numpy.ndarray.__sub__()用法及代碼示例
- Python Numpy numpy.ndarray.__mul__()用法及代碼示例
- Python Numpy numpy.ndarray.__truediv__()用法及代碼示例
- Python Numpy numpy.ndarray.__xor__()用法及代碼示例
- Python Numpy numpy.ndarray.__pos__()用法及代碼示例
- Python Numpy numpy.ndarray.__and__()用法及代碼示例
- Python Numpy numpy.ndarray.__neg__()用法及代碼示例
- Python Numpy numpy.ndarray.__isub__()用法及代碼示例
- Python Numpy numpy.ndarray.__rshift__()用法及代碼示例
- Python Numpy numpy.ndarray.__iadd__()用法及代碼示例
- Python Numpy numpy.ndarray.__pow__()用法及代碼示例
- Python Numpy numpy.ndarray.__lshift__()用法及代碼示例
- Python Numpy numpy.ndarray.__divmod__()用法及代碼示例
- Python Numpy numpy.ndarray.__invert__()用法及代碼示例
注:本文由純淨天空篩選整理自Jitender_1998大神的英文原創作品 Python | Numpy matrix.byteswap()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。