Python | Numpy matrix.tolist ()



Using the Numpy matrix.tolist () method, we can convert the matrix to a list using matrix.tolist () .

Syntax: matrix.tolist ()
Return: Return a new list

Example # 1:
In this example, we see that by passing a matrix, we can convert it to a list using matrix.tolist () .

# import important module into python

import numpy as np

  
# make a matrix with NumPy

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

 
# using the matrix.tolist () method

geek = gfg.tolist ()

 

print (geek)

Exit:

 [[4, 1, 12, 3]] 

Example # 2:

# 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] ` )

  
# applying the matrix.tolist () method

geek = gfg.tolist ()

 

print (geek)

Exit:

 [[4, 1, 9], [12, 3, 1], [4, 5, 6]]