Convert NumPy Array to List in Python: 5 Simple Methods

When I was working on a data analysis project where I needed to convert NumPy arrays back to Python lists for better compatibility with other parts of my application. While NumPy is fantastic for numerical operations, sometimes you need the flexibility of Python’s native lists.

In this article, I’ll show you several methods to convert NumPy arrays to Python lists, from the simplest approach to more specialized techniques for different array types and dimensions.

Let us get in..

Convert NumPy Array to List in Python

Now, I will explain how to convert a NumPy array to a list in Python.

Read NumPy Reverse Array in Python

Method 1 – Use the tolist() Method

The easiest way to convert a NumPy array to a list is to use the built-in tolist() method in Python.

import numpy as np

# Create a simple NumPy array
arr = np.array([1, 2, 3, 4, 5])

# Convert to list using tolist()
result = arr.tolist()

print(type(result)) 
print(result)       

Output:

<class 'list'>
[1, 2, 3, 4, 5]

I executed the above example code and added a screenshot below.

numpy array to list

This method works great for arrays of any dimension. For example, with a 2D array:

# Create a 2D NumPy array
arr_2d = np.array([[1, 2, 3], [4, 5, 6]])

# Convert to nested list
result_2d = arr_2d.tolist()

print(type(result_2d))  # <class 'list'>
print(result_2d)        # [[1, 2, 3], [4, 5, 6]]

The tolist() method preserves the structure of your array, converting multi-dimensional arrays into nested lists.

Check out NumPy Array to a String in Python

Method 2 – Use the list() Function

Another approach is to use Python’s built-in list() function. However, this method only works reliably for 1D arrays.

import numpy as np

arr = np.array([1, 2, 3, 4, 5])
result = [int(x) for x in arr]

print(type(result))
print(result)

Output:

<class 'list'>
[1, 2, 3, 4, 5]

I executed the above example code and added a screenshot below.

numpy to list

For multi-dimensional arrays, the list() function will create a list of NumPy arrays, not a nested list:

# Create a 2D NumPy array
arr_2d = np.array([[1, 2, 3], [4, 5, 6]])

# Convert using list()
result_2d = list(arr_2d)

print(type(result_2d))  # <class 'list'>
print(type(result_2d[0]))  # <class 'numpy.ndarray'>

This is why I recommend using tolist() for multi-dimensional arrays.

Read np.add.at() Function in Python

Method 3 – Use List Comprehension

If you need more control over the conversion process, you can use Python list comprehension:

import numpy as np

arr = np.array([1, 2, 3, 4, 5])
result = [int(x) for x in arr]

print(type(result))     
print(result)           

Output:

<class 'list'>
[1, 2, 3, 4, 5]

I executed the above example code and added a screenshot below.

array to list python

For 2D arrays, you can use nested list comprehension:

# Create a 2D NumPy array
arr_2d = np.array([[1, 2, 3], [4, 5, 6]])

# Convert using nested list comprehension
result_2d = [[cell for cell in row] for row in arr_2d]

print(type(result_2d))  # <class 'list'>
print(result_2d)        # [[1, 2, 3], [4, 5, 6]]

This method gives you the flexibility to transform elements during conversion if needed.

Check out Replace Values in NumPy Array by Index in Python

Method 4 – Convert Specific Data Types

When working with arrays of non-numeric data types in Python, the conversion process remains the same:

import numpy as np

# String array
str_arr = np.array(['apple', 'banana', 'cherry'])
str_list = str_arr.tolist()
print(str_list)  # ['apple', 'banana', 'cherry']

# Boolean array
bool_arr = np.array([True, False, True])
bool_list = bool_arr.tolist()
print(bool_list)  # [True, False, True]

# Mixed data types (stored as objects)
mixed_arr = np.array(['apple', 42, True], dtype=object)
mixed_list = mixed_arr.tolist()
print(mixed_list)  # ['apple', 42, True]

Using tolist() in NumPy provides a clean and reliable way to convert arrays, regardless of their data type, into native Python lists. It works seamlessly for strings, booleans, and even mixed-type object arrays.

Read np.diff() Function in Python

Method 5 – Convert Large Arrays Efficiently

For very large arrays, you might be concerned about memory usage. The good news is that tolist() is quite efficient:

import numpy as np
import time

# Create a large array
large_arr = np.arange(1_000_000)

# Time the conversion
start = time.time()
large_list = large_arr.tolist()
end = time.time()

print(f"Conversion took {end - start:.4f} seconds")
print(f"First 5 elements: {large_list[:5]}")
print(f"Last 5 elements: {large_list[-5:]}")

If you need to process large arrays in chunks, you can do so by slicing:

# Process a large array in chunks
large_arr = np.arange(1_000_000)
chunk_size = 100_000
all_chunks = []

for i in range(0, len(large_arr), chunk_size):
    chunk = large_arr[i:i+chunk_size].tolist()
    all_chunks.extend(chunk)

# all_chunks now contains all elements as a list

By converting each chunk with tolist(), you can gradually build a complete Python list without overwhelming system resources.

Read NumPy Filter 2D Array by Condition in Python

Real-World Applications

Let’s look at a more realistic example using US stock market data:

import numpy as np
import pandas as pd

# Create a NumPy array with stock prices for 5 days
stock_prices = np.array([
    [142.56, 157.96, 339.30, 267.56, 185.30],  # Monday
    [143.75, 159.22, 341.05, 268.91, 183.45],  # Tuesday
    [145.85, 158.46, 338.79, 271.65, 186.55],  # Wednesday
    [144.29, 160.03, 342.50, 269.37, 184.21],  # Thursday
    [146.82, 161.78, 345.12, 273.88, 188.39]   # Friday
])

# Stock symbols
symbols = ['AAPL', 'MSFT', 'TSLA', 'META', 'AMZN']

# Convert to list of dictionaries for JSON serialization
stock_data = []
for i, day_prices in enumerate(['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday']):
    day_data = {'day': day_prices}
    for j, symbol in enumerate(symbols):
        day_data[symbol] = stock_prices[i, j]
    stock_data.append(day_data)

print(stock_data[0])  # Monday's data

This approach is useful when you need to convert NumPy data to a format suitable for JSON serialization in web applications.

Converting NumPy arrays to Python lists is a common operation when moving between NumPy’s efficient numeric operations and Python’s more flexible data structures. The tolist() method is usually your best bet, offering a clean and efficient way to convert arrays of any dimension while preserving their structure.

You may like to read:

51 Python Programs

51 PYTHON PROGRAMS PDF FREE

Download a FREE PDF (112 Pages) Containing 51 Useful Python Programs.

pyython developer roadmap

Aspiring to be a Python developer?

Download a FREE PDF on how to become a Python developer.

Let’s be friends

Be the first to know about sales and special discounts.