20.5 C
London
Monday, June 2, 2025
HomePandas in PythonDataFrame Functions in PythonHow to Convert NumPy Array to List in Python (With Examples)

How to Convert NumPy Array to List in Python (With Examples)

Related stories

Learn About Opening an Automobile Repair Shop in India

Starting a car repair shop is quite a good...

Unlocking the Power: Embracing the Benefits of Tax-Free Investing

  Unlocking the Power: Embracing the Benefits of Tax-Free Investing For...

Income Splitting in Canada for 2023

  Income Splitting in Canada for 2023 The federal government’s expanded...

Can I Deduct Home Office Expenses on my Tax Return 2023?

Can I Deduct Home Office Expenses on my Tax...

Canadian Tax – Personal Tax Deadline 2022

  Canadian Tax – Personal Tax Deadline 2022 Resources and Tools...

You can use the following basic syntax to convert a NumPy array to a list in Python:

my_list = my_array.tolist()

The following examples show how to use this syntax in practice.

Example 1: Convert 1-Dimensional Array to List

The following code shows how to convert a 1-dimensional NumPy array to a list in Python:

import numpy as np

#create NumPy array
my_array = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
  
#convert NumPy array to list                
my_list = my_array.tolist()

#view list
print(my_list)

[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

#view object type
type(my_list)

list

Example 2: Convert Multi-Dimensional Array to List

The following code shows how to convert a multi-dimensional NumPy array to a list in Python:

import numpy as np

#create NumPy array
my_array = np.array([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
  
#convert NumPy array to list                
my_list = my_array.tolist()

#view list
print(my_list)

[[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]]

#view object type
type(my_list)

list

Example 3: Convert Multi-Dimensional Array to Flattened List

The following code shows how to convert a multi-dimensional NumPy array to a flattened list in Python:

import numpy as np

#create NumPy array
my_array = np.array([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
  
#convert NumPy array to flattened list                
my_list = my_array.flatten().tolist()

#view list
print(my_list)

[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

#view object type
type(my_list)

list

Additional Resources

The following tutorials explain how to perform other common conversions in Python:

How to Convert List to NumPy Array
How to Convert Pandas Series to NumPy Array
Convert Pandas DataFrame to NumPy Array

Subscribe

- Never miss a story with notifications

- Gain full access to our premium content

- Browse free from up to 5 devices at once

Latest stories