How to convert Numpy array to Python list?

Let’s check how to convert Numpy array to Python list.
convert numpy array to python list type

The 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'”.

Numpy array to Python list

Let’s use list function and convert Numpy array to Python list.


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 rank values in Numpy array?