  # Python | Numpy matrix.byteswap ()

NumPy | Python Methods and Functions

Using the ` Numpy matrix.byteswap () ` method, we can swap the bytes of an element a in a given matrix that has one or more dimensions. This will not work with a string or character matrix.

Syntax: `matrix.byteswap()`

Return: Return the byteswapped matrix

Example # 1:
In this example we see that using the ` matrix.byteswap () ` method we can swap the bytes of an element in a given matrix.

` `

 ` # import an important module into python ` ` import ` ` numpy as np `   ` # make a matrix with NumPy ` ` gfg = np.matrix ( `[1, 2, 3, 4]` ) `` ``   # using the matrix.byteswap () method ` ` geeks ` ` = gfg.byteswap () ``   print (geeks) `

` ` Exit:

` [[72057594037927936 144115188075855872 216172782113783808 288230376151711744]] `

Example # 2:

 ` # import 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] `` `) ` ` `  ` # using the matrix.byteswap () method ` ` geeks ` ` = gfg.byteswap () ``   print (geeks) `

Exit:

``` [[72057594037927936 144115188075855872 216172782113783808] [288230376151711744 360287970189639680 432345564227567616] [504403158265495552 57246460