October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

Convert a NumPy Array to a List in Python: 5 Methods

Use arr.tolist() for a nested Python list in most cases. Compare five conversion methods, see when flattening changes the shape, and learn how 0-D arrays behave.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For a nested Python list that follows an array’s dimensions, use arr.tolist(). It also converts NumPy scalar values to compatible built-in Python scalars. One exception: a zero-dimensional array returns a scalar, not a list.

Assume NumPy is imported as np and your array is named arr. The examples below show which method to use for nested output, a flat sequence, or explicit row-by-row conversion.

1. Use arr.tolist() for a nested Python list

This is the general-purpose choice. NumPy’s ndarray.tolist() documentation describes the result as an a.ndim-levels-deep nested list of Python scalars. It preserves the array’s dimensional structure in the lists and converts array scalars to compatible Python scalar types.

import numpy as np

arr = np.array([[1, 2], [3, 4]])
result = arr.tolist()

# result: [[1, 2], [3, 4]]

The returned containers and values are a copy; changing the list does not edit the original array.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

2. Use list(arr) for a one-dimensional array

For a 1-D array, list(arr) produces a Python list, but its elements remain NumPy scalar values. That differs from tolist(), which converts them to compatible built-in Python scalars.

arr = np.array([1, 2, 3])
result = list(arr)

# result: [np.int64(1), np.int64(2), np.int64(3)]
# Element types depend on the array's dtype and NumPy version.

For a 2-D array, list(arr) iterates over the first axis and returns row arrays, not a nested Python list. NumPy’s examples illustrate this distinction between list() and tolist().

3. Use list(map(list, arr)) for explicit 2-D row conversion

If the array is two-dimensional and you want to convert each row explicitly, map list() over the rows:

arr = np.array([[1, 2], [3, 4]])
result = list(map(list, arr))

# result: [[1, 2], [3, 4]]

This is a row-by-row conversion for 2-D input. For arrays with more dimensions, it does not recursively convert every nested level; use arr.tolist() instead.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

4. Use arr.flatten().tolist() when you want one flat list

Flattening removes the original multidimensional arrangement before the values are converted to a list. Choose it only when you want a single sequence rather than nested rows.

arr = np.array([[1, 2], [3, 4]])
result = arr.flatten().tolist()

# result: [1, 2, 3, 4]

5. Use a list comprehension when you want to show the iteration

For 1-D input, a comprehension makes the iteration visible, but its elements remain NumPy scalars, as with list(arr).

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

For 2-D input, convert each row with tolist() to preserve the two-level shape as Python lists:

arr = np.array([[1, 2], [3, 4]])
result = [row.tolist() for row in arr]

# result: [[1, 2], [3, 4]]

For arbitrary dimensions, prefer the recursive arr.tolist() method rather than adding nested iteration manually.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Which method should you choose?

Method Input dimensionality Output shape Element types
arr.tolist() Any; a 0-D array is a special case Nested lists following the array dimensions; 0-D input returns a scalar Compatible Python scalars
list(arr) Best suited to 1-D One list for 1-D input; row arrays for 2-D input NumPy scalars for 1-D input
list(map(list, arr)) 2-D List of row lists Values yielded by applying Python list() to each row
arr.flatten().tolist() Any array with values One flat list; original arrangement is removed Compatible Python scalars
List comprehension 1-D or 2-D, depending on expression 1-D list, or two-level list with [row.tolist() for row in arr] NumPy scalars for [x for x in arr]; compatible Python scalars for converted rows

Handle zero-dimensional arrays and round trips carefully

A 0-D array returns a scalar

Because a zero-dimensional array has no list-shaped dimension, arr.tolist() returns a scalar. If you specifically need a one-item list, wrap the scalar explicitly:

arr = np.array(7)
result = [arr.item()]

# result: [7]

This creates a different output shape from calling arr.tolist().

Rebuilding an array may lose precision

You can construct an array from a list with np.array(arr.tolist()), but NumPy warns that converting to a list and back can sometimes lose precision. Do not assume this round trip is always lossless; if preserving the array representation matters, avoid using a Python list as an intermediate format.

The API details here correspond to NumPy’s stable documentation, whose version label is 2.5: tolist(), array creation and examples, and data types.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.