Skip to content
Related Articles

Related Articles

Python | Numpy ndarray.tolist()
  • Last Updated : 27 Mar, 2019

With the help of numpy.ndarray.tolist() method, we can have the list of data elements which is converted from an ndarray using ndarray.tolist() method.

Syntax: ndarray.tolist()

Parameters: none

Returns: The possibly nested list of array elements.

Example #1 :
In this example, we can see that by using ndarray.tolist() method, we can have the list of data items in ndarray.






# import the important module in python
import numpy as np
        
# make an array with numpy
gfg = np.array([1, 2, 3, 4, 5])
        
# applying ndarray.tolist() method
print(gfg.tolist())
Output:
[1, 2, 3, 4, 5]

Example #2 :




# import the important module in python
import numpy as np
        
# make an array with numpy
gfg = np.array([[1, 2, 3, 4, 5],
                [6, 5, 4, 3, 2]])
        
# applying ndarray.tolist() method
print(gfg.tolist())
Output:
[[1, 2, 3, 4, 5], [6, 5, 4, 3, 2]]

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

My Personal Notes arrow_drop_up
Recommended Articles
Page :