Python | Numpy matrix.tobytes ()

NumPy | Python Methods and Functions

With the Numpy matrix.tobytes () method we can find the matrix bytecode using the matrix.tobytes () method.

Syntax: matrix.tobytes ()
Return: Return byte code for matrix

Example # 1:
In this example we can see that using matrix.tobytes ( ) we can find the bytecode for the given matrix.

# import important module in python

import numpy as np

 
# make a matrix with NumPy

gfg = np.matrix ( `[4, 1; 12, 3] ` )

  
# applying the matrix.tobytes () method

geek = gfg.tobytes ()

  

print (geek)

Exit:

b`x04x00x00x00x00x00x00x00x01x00x00x00x00x00x00x00x0cx00x00x00x00x00x00x00x03x00x00x00x00x00x00x00 ′

# import important module in python

import numpy as np

 
# make a matrix with NumPy

gfg = np.matrix ( `[ 4, 1, 9; 12, 3, 1; 4, 5, 6] ` )

  
# using the matrix.tobytes () method

geek = gfg.tobytes ()

 

print (geek)

Exit:

b`x04x00x00x00x00x00x00x00x01x00x00x00x00x00x00x00 x00x00x00x00x00x00x00x0cx00x00x00x00x00x00x00x03x00x00x00x00x00x00x00x01x00x00x00x00x00x00x00x04x00x00x00x00x00x00x00x05x00x00x00x00x00x00x00x06x00x00x00x00x00x00x00 `



Get Solution for free from DataCamp guru