Not sure if I understood the question correctly, but does this work for you?

import numpy as np
A = [[1,2,3],[4,5,6],[7,8,9]]
A = np.array(A)

If A is a list of numpy array, how about this:

Ah = np.vstack(A)
Av = np.hstack(A)
Answer from YS-L on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-using-2d-arrays-lists-the-right-way
Using 2D arrays/lists in Python - GeeksforGeeks
The code below, compares two ways of initializing a 2D list in Python. Using list multiplication ([[0]*cols]*rows) creates multiple references to the same inner list, causing aliasing where changes affect all rows. Using a nested list comprehension creates a separate list for each row, avoiding aliasing and correctly forming a 2D array.
Published: December 20, 2025
๐ŸŒ
Note.nkmk.me
note.nkmk.me โ€บ home โ€บ python
Convert 1D Array to 2D Array in Python (numpy.ndarray, list) | note.nkmk.me
May 15, 2023 - l = [0, 1, 2, 3, 4, 5] print(np.array(l).reshape(-1, 3).tolist()) # [[0, 1, 2], [3, 4, 5]] print(np.array(l).reshape(3, -1).tolist()) # [[0, 1], [2, 3], [4, 5]] ... See the following article on how to convert numpy.ndarray and list to each other. ... If NumPy is not available, you can still achieve the transformation using list comprehensions, range(), and slices. ... def convert_1d_to_2d(l, cols): return [l[i:i + cols] for i in range(0, len(l), cols)] l = [0, 1, 2, 3, 4, 5] print(convert_1d_to_2d(l, 2)) # [[0, 1], [2, 3], [4, 5]] print(convert_1d_to_2d(l, 3)) # [[0, 1, 2], [3, 4, 5]] print(convert_1d_to_2d(l, 4)) # [[0, 1, 2, 3], [4, 5]]
Top answer
1 of 4
23

Not sure if I understood the question correctly, but does this work for you?

import numpy as np
A = [[1,2,3],[4,5,6],[7,8,9]]
A = np.array(A)

If A is a list of numpy array, how about this:

Ah = np.vstack(A)
Av = np.hstack(A)
2 of 4
8

If I understood correctly what you're asking, you have a case where numpy did not convert array of arrays into 2d array. This can happen when your arrays are not of the same size. Example:

Automatic conversion to 2d array:

import numpy as np
a = np.array([np.array([1,2,3]),np.array([2,3,4]),np.array([6,7,8])])
print a

Output:

>>>[[1 2 3]
    [2 3 4]
    [6 7 8]]

No automatic conversion (look for the change in the second subarray):

import numpy as np
b = np.array([np.array([1,2,3]),np.array([2,3,4,5]),np.array([6,7,8])])
print b

Output:

>>>[array([1, 2, 3]) array([2, 3, 4, 5]) array([6, 7, 8])]

I found a couple of ways of converting an array of arrays to 2d array. In any case you need to get rid of subarrays which have different size. So you will need a mask to select only "good" subarrays. Then you can use this mask with list comprehensions to recreate array, like this:

import numpy as np

a = np.array([np.array([1,2,3]),np.array([2,3,4,5]),np.array([6,7,8])])
mask = np.array([True, False, True])

c = np.array([element for (i,element) in enumerate(a) if mask[i]])

print a
print c

Output:

>>>>[array([1, 2, 3]) array([2, 3, 4, 5]) array([6, 7, 8])]
>>>>[[1 2 3]
     [6 7 8]]

Or you can delete "bad" subarrays and use vstack(), like this:

import numpy as np

a = np.array([np.array([1,2,3]),np.array([2,3,4,5]),np.array([6,7,8])])
mask = np.array([True, False, True])

d = np.delete(a,np.where(mask==False))
e = np.vstack(d)

print a
print e

Output:

>>>>[array([1, 2, 3]) array([2, 3, 4, 5]) array([6, 7, 8])]
>>>>[[1 2 3]
     [6 7 8]]

I believe second method would be faster for large arrays, but I haven't tested the timing.

๐ŸŒ
Finxter
blog.finxter.com โ€บ home โ€บ learn python blog โ€บ python list to 2d array โ€“ the ultimate conversion guide
Python List to 2D Array - The Ultimate Conversion Guide - Be on the Right Side of Change
October 27, 2023 - 2D arrays, also known as matrices or two-dimensional lists, are lists of lists where each inner list represents a row in the 2D array. In Python, you can create a 2D array using nested lists.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ how to convert a list to a 2d array?
r/learnpython on Reddit: How to convert a list to a 2D array?
May 5, 2020 -

I have a list:

data=[1,2,3,4,5,6,7,...]

and I want to transform it into a 2-dimensional array, with 5 columns and 10 rows

How can I do it?

๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ several lists into one 2d matrix
r/learnpython on Reddit: several lists into one 2d matrix
August 15, 2023 -

Hello, I have a simple question : For example, I have 3 lists a,b,c , and I want to join them into one big 2d array called d, how do I do it:

a= [1,2,3]

b= [4,5,6]

c= [7,8,9]

result wanted :

d= [

[1,2,3],

[4,5,6],

[7,8,9]

]

thank you !!!

Find elsewhere
๐ŸŒ
Snakify
snakify.org โ€บ two-dimensional lists (arrays)
Two-dimensional lists (arrays) - Learn Python 3 - Snakify
We have already tried to explain that a for-loop variable in Python can iterate not only over a range(), but generally over all the elements of any sequence. Sequences in Python are lists and strings (and some other objects that we haven't met yet). Look how you can print a two-dimensional array, using this handy feature of loop for:
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python-using-2d-arrays-lists-the-right-way
Python | Using 2D arrays/lists the right way - GeeksforGeeks
The code then shows another approach using a nested list comprehension to create the 2D array arr. This method avoids aliasing by creating a new list for each row, resulting in a proper 2D array. ... # Python 3 program to demonstrate working # of method 1 and method 2.
Published: June 20, 2024
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 29149286 โ€บ list-of-lists-to-2d-array-in-python
List of Lists to 2D Array in Python - Stack Overflow
If so, is there any other type of data that I can use? Is setting it to Arrayobject ensures that I can combine str/int inside of it? ... You need to use Array.CreateInstance to create 2D arrays, and they have to be of a single type.
๐ŸŒ
CodeSpeedy
codespeedy.com โ€บ home โ€บ how to create 2d array from list of lists in python
Create 2D Array From List in Python - CodeSpeedy
April 11, 2019 - Using NumPy we can easily create a 2D array from list of lists in Python. This type of array also known as ranked two array.
Top answer
1 of 3
7

If your lists are NOT of the same length (in each nested dimension) you CANT do a traditional conversion to a NumPy array because it's necessary for a NumPy array of 2D or above to have the same number of elements in its first dimension.

So you cant convert [[1,2],[3,4,5]] to a numpy array directly. Applying np.array will give you a 2 element numpy array where each element is a list object as - array([list([1, 2]), list([3, 4, 5])], dtype=object). I believe this is the issue you are facing.

You cant create a 2D matrix for example that looks like -

[[1,2,3,?],
 [4,5,6,7]]

What you may need to do is pad the elements of each list of lists of lists to a fixed length (equal lengths for each dimension) before converting to a NumPy array.

I would recommend iterating over each of the lists of lists of lists as done in the code I have written below to flatten your data, then transforming it the way you want.


If your lists are of the same length, then should not be a problem with numpy version 1.18.5 or above.

a = [[[1,2],[3,4]],[[5,6],[7,8]]]
np.array(a)
array([[[1, 2],
        [3, 4]],

       [[5, 6],
        [7, 8]]])

However, if you are unable to still work with the list of list of lists, then you may need to iterate over each element first to flatten the list and then change it into a numpy array with the required shape as below -

a = [[[1,2],[3,4]],[[5,6],[7,8]]]
flat_a = [item for sublist in a for subsublist in sublist for item in subsublist]
np.array(flat_a).reshape(2,2,2)
array([[[1, 2],
        [3, 4]],

       [[5, 6],
        [7, 8]]])
2 of 3
0

Try this:

>>> import numpy as np
>>> a = np.array([[[1,2],[3,4],[5,6]],[[7,8],[9,10],[11,12]]])
>>> a
array([[[ 1,  2],
        [ 3,  4],
        [ 5,  6]],

       [[ 7,  8],
        [ 9, 10],
        [11, 12]]])
>>> a.reshape(4,-1)
array([[ 1,  2,  3],
       [ 4,  5,  6],
       [ 7,  8,  9],
       [10, 11, 12]])


>>> a.reshape(1,-1)
array([[ 1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12]])
๐ŸŒ
w3resource
w3resource.com โ€บ python-exercises โ€บ numpy โ€บ convert-a-nested-python-list-to-a-2d-numpy-array-and-print.php
Convert a nested Python list to a 2D NumPy array and print
Convert to 2D NumPy Array: Use np.array() to convert the nested list into a 2D NumPy array. Print 2D Array: Output the resulting 2D NumPy array to verify the conversion. ... Write a Numpy program to convert a nested Python list with inconsistent ...
๐ŸŒ
APXML
apxml.com โ€บ courses โ€บ essential-numpy-pandas โ€บ chapter-2-getting-started-numpy-arrays โ€บ creating-arrays-from-lists
Creating Arrays from Python Lists
Here, the list of three lists, each containing three integers, is transformed into a 2-dimensional array (a matrix) with 3 rows and 3 columns. NumPy arranges the data accordingly. Transformation of a nested Python list into a 2D NumPy ndarray. For NumPy to create a standard multi-dimensional ...
๐ŸŒ
Guru99
guru99.com โ€บ home โ€บ python โ€บ python 2d arrays: two-dimensional list examples
Python 2D Arrays: Two-Dimensional List Examples
July 10, 2026 - Array is a data structure used to store elements. An array can only store similar types of elements. A Two Dimensional is defined as an Array inside the Array. The index of the array starts with 0 and ends with a size of array minus 1. We can create โ€˜nโ€™ number of arrays in an array. In the above image, we can see that an index uniquely identifies each array element. We can create a two-dimensional array(list) with rows and columns. ... #creare 2D array with 4 rows and 5 columns array=[[23,45,43,23,45],[45,67,54,32,45],[89,90,87,65,44],[23,45,67,32,10]] #display print(array) #get the first row print(array[0]) #get the third row print(array[2]) #get the first row third element print(array[0][2]) #get the third row forth element print(array[2][3])
๐ŸŒ
iO Flood
ioflood.com โ€บ blog โ€บ python-2d-array
Python 2D Array with Lists | Guide (With Examples)
February 10, 2024 - Each inner list [1, 2, 3], [4, 5, 6], and [7, 8, 9] represents a row in the 2D array. When we print the array, we get the output as a nested list, which is the Pythonic way of representing a 2D array. This is a basic way to create a 2D array in Python, but thereโ€™s much more to learn about ...
๐ŸŒ
Processing
py.processing.org โ€บ tutorials โ€บ 2dlists
Two-Dimensional Lists \ Tutorials
Python Mode for Processing extends the Processing Development Environment with the Python programming language.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python-convert-1d-list-to-2d-list-of-variable-length
Convert 1D list to 2D list of variable length- Python | GeeksforGeeks
February 1, 2025 - When converting a 1D list to a 2D list of variable lengths, islice() from itertools module offers an efficient way to slice the list into chunks without storing the entire list in memory.
๐ŸŒ
Dot Net Perls
dotnetperls.com โ€บ 2d-python
Python - 2D List Examples - Dot Net Perls
Version 2 This code accesses the flattened list, using an expression to compute the correct index. Result Accessing the element at position coordinates 1, 2 is slightly faster in the flattened list. import time # Nested, 3x2. nested_list = [] nested_list.append([ ... Python supports a special "array" from the array module. An integer array is more compact in memory than an integer list. We can create a flattened 2D array.