Python | Numpy ndarray.tolist ()



Using the numpy.ndarray.tolist() method we can get a list of data items that is converted from ndarray using ndarray.tolist () .

Syntax: ndarray.tolist ()

Parameters: none

Returns: The possibly nested list of array elements.

Example # 1:
In this example, we can see that with ndarray.tolist () we can get a list of data items in ndarray.

# import an important module into python

import numpy as np

 
# make an array with NumPy

gfg =   np.array ([ 1 , 2 , 3 , 4 , 5 ])

 
# applying the ndarray.tolist () method

print (gfg.tolist ())

Exit:

 [1, 2, 3, 4, 5] 

Example # 2:

Exit:

 [[1, 2, 3, 4, 5], [6, 5, 4, 3, 2]] 

# import important module in python

import numpy as np

 
# make array with NumPy

gfg = np.array ([[ 1 , 2 , 3 , 4 , 5 ],

  [ 6 , 5 , 4 , 3 , 2 ]])

 
# applying the ndarray.tolist () method

print (gfg.tolist ())