This works:

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

So this should work too:

nd_a = np.array([[x for x in y] for y in a])
Answer from Marijn van Vliet on Stack Overflow
🌐
W3Schools
w3schools.com β€Ί python β€Ί numpy β€Ί numpy_creating_arrays.asp
NumPy Creating Arrays
Like in above code it shows that arr is numpy.ndarray type. To create an ndarray, we can pass a list, tuple or any array-like object into the array() method, and it will be converted into an ndarray: ... A dimension in arrays is one level of array depth (nested arrays). nested array: are arrays that have arrays as their elements. 0-D arrays, or Scalars, are the elements in an array. Each value in an array is a 0-D array.
🌐
NumPy
numpy.org β€Ί doc β€Ί stable β€Ί user β€Ί basics.creation.html
Array creation β€” NumPy v2.5 Manual
Lists and tuples are defined using [...] and (...), respectively. Lists and tuples can define ndarray creation: a list of numbers will create a 1D array, a list of lists will create a 2D array, further nested lists will create higher-dimensional arrays. In general, any array object is called ...
🌐
Sentry
sentry.io β€Ί sentry answers β€Ί python β€Ί define a two-dimensional array in python
Python Define a Two-Dimensional Array or Matrix | Sentry
September 23, 2026 - Create a 2D array in Python using numpy.zeros for matrix operations, or a nested list comprehension if you want to avoid the numpy dependency
🌐
Python Guides
pythonguides.com β€Ί python-numpy-2d-array
Create A 2D NumPy Array In Python (5 Simple Methods)
May 9, 2025 - A 2D array in Python is a table of values arranged in rows and columns. Python has no built-in 2D array type, so you use either a nested list (a list of rows, like [[1, 2], [3, 4]]) or a NumPy 2D array created with np.array(), np.zeros() and ...
🌐
NumPy
numpy.org β€Ί doc β€Ί stable β€Ί reference β€Ί arrays.ndarray.html
The N-dimensional array (ndarray) β€” NumPy v2.5 Manual
The type of items in the array is specified by a separate data-type object (dtype), one of which is associated with each ndarray. As with other container objects in Python, the contents of an ndarray can be accessed and modified by indexing or slicing the array (using, for example, N integers), and via the methods and attributes of the ndarray.
🌐
Drbeane
drbeane.github.io β€Ί python_dsci β€Ί pages β€Ί array_2d.html
2-Dimensional Arrays β€” Python for Data Science
Notice that the array that is printed above is not displayed in the form of a column. In fact, when slicing a single row or a column out of a 2D array, the result is returned as a simple 1D array. Every Numpy array comes equipped with a shape attribute that we can use to determine the shape of the array.
Find elsewhere
🌐
Medium
medium.com β€Ί @bouimouass.o β€Ί what-does-a-numpy-2d-array-look-like-in-python-38752ccde895
What does a numpy 2D array look like in python? | by Omar | Medium
July 23, 2023 - The first row contains the numbers 1, 2, 3, and 4. The second row contains the numbers 5, 6, 7, and 8. The third row contains the numbers 9, 10, 11, and 12. You can also create a 2D NumPy array using the arange() function.
🌐
freeCodeCamp
freecodecamp.org β€Ί news β€Ί multi-dimensional-arrays-in-python
Multi-Dimensional Arrays in Python – Matrices Explained with Examples
December 11, 2025 - In Python, you can create multi-dimensional arrays using various libraries, such as NumPy, Pandas, and TensorFlow.
Top answer
1 of 7
1263

You're technically trying to index an uninitialized array. You have to first initialize the outer list with lists before adding items; Python calls this "list comprehension".

# Creates a list containing 5 lists, each of 8 items, all set to 0
w, h = 8, 5
Matrix = [[0 for x in range(w)] for y in range(h)] 

#You can now add items to the list:

Matrix[0][0] = 1
Matrix[6][0] = 3 # error! range... 
Matrix[0][6] = 3 # valid

Note that the matrix is "y" address major, in other words, the "y index" comes before the "x index".

print Matrix[0][0] # prints 1
x, y = 0, 6 
print Matrix[x][y] # prints 3; be careful with indexing! 

Although you can name them as you wish, I look at it this way to avoid some confusion that could arise with the indexing, if you use "x" for both the inner and outer lists, and want a non-square Matrix.

2 of 7
487

If you really want a matrix, you might be better off using numpy. Matrix operations in numpy most often use an array type with two dimensions. There are many ways to create a new array; one of the most useful is the zeros function, which takes a shape parameter and returns an array of the given shape, with the values initialized to zero:

>>> import numpy
>>> numpy.zeros((5, 5))
array([[ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.]])

Here are some other ways to create 2-d arrays and matrices (with output removed for compactness):

numpy.arange(25).reshape((5, 5))         # create a 1-d range and reshape
numpy.array(range(25)).reshape((5, 5))   # pass a Python range and reshape
numpy.array([5] * 25).reshape((5, 5))    # pass a Python list and reshape
numpy.empty((5, 5))                      # allocate, but don't initialize
numpy.ones((5, 5))                       # initialize with ones

numpy provides a matrix type as well, but it is no longer recommended for any use, and may be removed from numpy in the future.

🌐
GeeksforGeeks
geeksforgeeks.org β€Ί python β€Ί numpy-array-in-python
NumPy Array in Python - GeeksforGeeks
July 1, 2026 - Python Β· import numpy as np arr1 ... a 1D array containing a single sequence of elements. np.array([[1, 2], [3, 4]]) creates a 2D array with rows and columns....
🌐
w3resource
w3resource.com β€Ί python-exercises β€Ί numpy β€Ί python-numpy-exercise-37.php
Python NumPy: Create a 2-dimensional array of size 2 x 3 - w3resource
August 29, 2025 - Write a NumPy program to create a 2-dimensional array of size 2 x 3 (composed of 4-byte integer elements), also print the shape, type and data type of the array. ... # Importing the NumPy library with an alias 'np' import numpy as np # Creating ...
🌐
AskPython
askpython.com β€Ί python β€Ί array β€Ί multidimensional-arrays
Multidimensional Arrays in Python: A Complete Guide - AskPython
February 27, 2023 - #To install the Numpy package pip install numpy #To import the Numpy package import numpy as np Β· An array of arrays is a simple definition that applies to the two-dimensional array.
🌐
Programiz
programiz.com β€Ί python-programming β€Ί numpy β€Ί ndarray-creation
NumPy N-D Array Creation (With Examples)
May 22, 2023 - We saw how to create N-d NumPy arrays from Python lists. Now we'll see how we can create them from scratch. To create multidimensional arrays from scratch we use functions such as ... The np.zeros() function allows us to create N-D arrays filled with all zeros. For example, ... # create 2D array with 2 rows and 3 columns filled with zeros array1 = np.zeros((2, 3)) print("2-D Array: ") print(array1)
🌐
MLJAR
mljar.com β€Ί answers β€Ί define-two-dimensional-array-python
Define two-dimensional array in Python
array[2][2] = 5 # valid array[7][2] = 3 # error Β· This way is much easier. You can use zeros function from numpy to create 2D array with all values set to zero: import numpy array = numpy.zeros((4,4)) REMEMBER Even though the second version is easier, the first one is better for this operation unless we need any matrix operations.
🌐
NumPy
numpy.org β€Ί devdocs β€Ί user β€Ί basics.creation.html
Array creation β€” NumPy v2.6.dev0 Manual
Lists and tuples are defined using [...] and (...), respectively. Lists and tuples can define ndarray creation: a list of numbers will create a 1D array, a list of lists will create a 2D array, further nested lists will create higher-dimensional arrays. In general, any array object is called ...
🌐
NumPy
numpy.org β€Ί devdocs β€Ί user β€Ί absolute_beginners.html
NumPy: the absolute basics for beginners β€” NumPy v2.6.dev0 Manual
Using np.newaxis will increase the dimensions of your array by one dimension when used once. This means that a 1D array will become a 2D array, a 2D array will become a 3D array, and so on.
🌐
NumPy
numpy.org β€Ί doc β€Ί 2.4 β€Ί reference β€Ί arrays.ndarray.html
The N-dimensional array (ndarray) β€” NumPy v2.4 Manual
The type of items in the array is specified by a separate data-type object (dtype), one of which is associated with each ndarray. As with other container objects in Python, the contents of an ndarray can be accessed and modified by indexing or slicing the array (using, for example, N integers), and via the methods and attributes of the ndarray.