Open In App

Python | Numpy matrix.byteswap()

Last Updated : 10 Apr, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

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


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


Output:

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

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads