How to Convert NumPy Array to Python List (Using .tolist() and list() Methods)

Let’s see how to convert NumPy array to Python list using the preferred ndarray.tolist() method or the built-in list() constructor for seamless type conversion.

convert numpy array to python list type

Check the Numpy Array Type

Let’s create Numpy array and check the type.

import numpy as np

numpy_array = np.array([1, 2, 3])
print(numpy_array)
print(type(numpy_array))

python_list = list(numpy_array)
print(python_list)
print(type(python_list))

Data type of this array is “class ‘numpy.ndarray'”.

See also  How to convert array to binary?

Numpy array to Python list

Both numpy_array.tolist() and list(numpy_array) effectively convert NumPy array to Python list, with tolist() being NumPy’s native method that properly handles multi-dimensional arrays and nested structures.


import numpy as np

numpy_array = np.array([1, 2, 3])
print(numpy_array)
print(type(numpy_array))

python_list = list(numpy_array)
print(python_list)
print(type(python_list))

Thanks to that array change to list (see commas). Also data type change to “class ‘list'”.

See also  How to Plot cos(x) in Python Using Matplotlib and NumPy (Cosine Function Graph Tutorial)