Convert Numpy Array to List

NumPy – Convert Array to a Python List

To convert a Numpy Array into List in Python, call numpy.tolist() function and pass the numpy array as argument to this function.

The syntax to call numpy.tolist() to convert a numpy array into list is

numpy.tolist(arr)

where arr is a numpy array.

Return Value

numpy.tolist() returns an object of type list.

Example

In this example, we take a numpy array in arr, and convert this numpy array into list using numpy.tolist().

Python Program

import numpy

arr = numpy.array([[1, 2], [3, 4]])
x = arr.tolist()

print("Numpy Array :\n", arr)
print("\nList :\n", x)
Run

Output

Numpy Array :
 [[1 2]
 [3 4]]

List :
[[1, 2], [3, 4]]

Summary

In this Numpy Tutorial of Python Examples, we learned how to convert a list into a numpy array, with the help of example program.