Python | Numpy matrix.byteswap()
Last Updated :
10 Apr, 2019
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 numpy as np
gfg = np.matrix( '[1, 2, 3, 4]' )
geeks = gfg.byteswap()
print (geeks)
|
Output:
[[ 72057594037927936 144115188075855872 216172782113783808
288230376151711744]]
Example #2 :
import numpy as np
gfg = np.matrix( '[1, 2, 3; 4, 5, 6; 7, 8, 9]' )
geeks = gfg.byteswap()
print (geeks)
|
Output:
[[ 72057594037927936 144115188075855872 216172782113783808]
[288230376151711744 360287970189639680 432345564227567616]
[504403158265495552 576460752303423488 648518346341351424]]
Share your thoughts in the comments
Please Login to comment...