How to convert NumPy array to list ?
In this article, we will discuss how to convert NumPy arrays to a list. We can convert the Numpy array to the list by tolist() method, we can have a list of data element which is converted from an array using this method.
Syntax: ndarray.tolist()
Parameters: none
Returns: The possibly nested list of array elements.
Approach
- Import required module.
- Create array.
- Display array and class type.
- Use tolist() method to convert the array.
- Display list and class type.
Example 1: One Dimensional Array
Python
# import moduleimport numpy as np # create arrayprint("\nArray:")arr = np.array([1, 2, 4, 5]) print(arr)print(type(arr)) # apply methodlis = arr.tolist() # display listprint("\nList:")print(lis)print(type(lis)) |
Output:

Example 2: Multidimensional Array
Python3
# import moduleimport numpy as np # create arrayprint("\nArray:")arr = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])print(arr)print(type(arr)) # apply methodlis = arr.tolist() # display listprint("\nList:")print(lis)print(type(lis)) |
Output:



