📜  Python| numpy matrix.byteswap()

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

Python| numpy matrix.byteswap()

借助Numpy 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]]