Python | Numpy matrix.tostring ()

NumPy | Python Methods and Functions | String Variables

Using the Numpy matrix.tostring () method, we can find the string format bytecode for a matrix using matrix.tostring () .

Syntax: matrix.tostring ()
Return: Return byte code string for matrix

Example # 1:
In this example we can see that with matrix.tostring () we can find the bytecode in string format for the given matrix.

# import important module into python

import numpy as np

 
# make a matrix with NumPy

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

  
# using the matrix.tostring () method

geek = gfg.tostring ()

 

print (geek)

Output:

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.tostring () method

geek = gfg.tostring ()

 

print (geek)

Exit:

b`x04x00x00x00x00x00x00x00x01x00x00x00x00x00x00x00 x00x00x00x00x00x00x00x0cx00x00x00x00x00x00x00x03x00x00x00x00x00x00x00x01x00x00x00x00x00x00x00x04x00x00x00x00x00x00x00x05x00x00x00x00x00x00x00x06x00x00x00x00x00x00x00 `



Get Solution for free from DataCamp guru