Wednesday, July 3, 2024
HomeLanguagesPythonPython | Numpy matrix.byteswap()

Python | Numpy matrix.byteswap()

With the help of Numpy matrix.byteswap() method, we are able to swap the bytes place of the an element in the given matrix having one or more dimension. It would not work on matrix of type string or character.

Syntax : matrix.byteswap()

Return : Return the byteswapped matrix

Example #1 :
In this example we can see that with the help of matrix.byteswap() method we are able to swap the place of bytes of an element in a given matrix.




# 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
neveropen = gfg.byteswap()
     
print(neveropen)


Output:

[[ 72057594037927936 144115188075855872 216172782113783808
  288230376151711744]]

Example #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
neveropen = gfg.byteswap()
     
print(neveropen)


Output:

[[ 72057594037927936 144115188075855872 216172782113783808]
 [288230376151711744 360287970189639680 432345564227567616]
 [504403158265495552 576460752303423488 648518346341351424]]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments