Friday, September 26, 2025
HomeLanguagesPython | 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]]
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32320 POSTS0 COMMENTS
Milvus
84 POSTS0 COMMENTS
Nango Kala
6683 POSTS0 COMMENTS
Nicole Veronica
11854 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11910 POSTS0 COMMENTS
Shaida Kate Naidoo
6795 POSTS0 COMMENTS
Ted Musemwa
7071 POSTS0 COMMENTS
Thapelo Manthata
6755 POSTS0 COMMENTS
Umr Jansen
6762 POSTS0 COMMENTS