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 OverflowW3Schools
w3schools.com โบ python โบ numpy โบ numpy_creating_arrays.asp
NumPy Creating Arrays
An array that has 1-D arrays as its elements is called a 2-D array. These are often used to represent matrix or 2nd order tensors. NumPy has a whole sub module dedicated towards matrix operations called numpy.mat
DataCamp
campus.datacamp.com โบ courses โบ intro-to-python-for-data-science โบ chapter-4-numpy
2D NumPy Arrays | Python
The arrays np_height and np_weight are one-dimensional arrays, but it's perfectly possible to create 2 dimensional, three dimensional, heck even seven dimensional arrays! Let's stick to 2 in this video though. You can create a 2D numpy array from a regular Python list of lists.
07:43
NumPy multidimensional arrays are easy! ๐ง - YouTube
16:05
NumPy Techniques and Practical Examples: Populating & Changing ...
08:16
2D Numpy Arrays for Data Science | Complete Python Tutorial - YouTube
How to Create 1D, 2D, and 3D Arrays in NumPy
05:14
Python Two Dimensional Numpy Arrays - YouTube
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.
W3Schools
w3schools.com โบ python โบ numpy โบ numpy_array_reshape.asp
NumPy Array Reshaping
import numpy as np arr = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) newarr = arr.reshape(2, 3, 2) print(newarr) Try it Yourself ยป ยท Yes, as long as the elements required for reshaping are equal in both shapes. We can reshape an 8 elements 1D array into 4 elements in 2 rows 2D array but we cannot reshape it into a 3 elements 3 rows 2D array as that would require 3x3 = 9 elements.
Top answer 1 of 3
21
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])
2 of 3
11
To create a new array, it seems numpy.zeros is the way to go
import numpy as np
a = np.zeros(shape=(x, y))
You can also set a datatype to allocate it sensibly
>>> np.zeros(shape=(5,2), dtype=np.uint8)
array([[0, 0],
[0, 0],
[0, 0],
[0, 0],
[0, 0]], dtype=uint8)
>>> np.zeros(shape=(5,2), dtype="datetime64[ns]")
array([['1970-01-01T00:00:00.000000000', '1970-01-01T00:00:00.000000000'],
['1970-01-01T00:00:00.000000000', '1970-01-01T00:00:00.000000000'],
['1970-01-01T00:00:00.000000000', '1970-01-01T00:00:00.000000000'],
['1970-01-01T00:00:00.000000000', '1970-01-01T00:00:00.000000000'],
['1970-01-01T00:00:00.000000000', '1970-01-01T00:00:00.000000000']],
dtype='datetime64[ns]')
See also
- How do I create an empty array/matrix in NumPy?
- np.full(size, 0) vs. np.zeros(size) vs. np.empty()
NumPy
numpy.org โบ doc โบ stable โบ reference โบ arrays.ndarray.html
The N-dimensional array (ndarray) โ NumPy v2.5 Manual
An ndarray is a (usually fixed-size) multidimensional container of items of the same type and size. The number of dimensions and items in an array is defined by its shape, which is a tuple of N non-negative integers that specify the sizes of each dimension. The type of items in the array is ...
Drbeane
drbeane.github.io โบ python_dsci โบ pages โบ array_2d.html
2-Dimensional Arrays โ Python for Data Science
The arrays we have worked with ... dimensional arrays. In this lesson, we will work exclusively with 2D arrays, which consist of several values arranged into ordered rows and columns....
Python Guides
pythonguides.com โบ python-numpy-2d-array
Create A 2D NumPy Array In Python (5 Simple Methods)
May 16, 2025 - Learn 5 practical methods to create 2D NumPy arrays in Python. Perfect for data analysis, with real-world examples using sales data, random initialization, and more
OpenGenus
iq.opengenus.org โบ 2d-array-in-numpy
2D Arrays in NumPy (Python)
October 28, 2022 - For working with numpy we need to first import it into python code base. ... To get a specific element from an array use arr[r,c] here r specifies row number and c column number.
freeCodeCamp
freecodecamp.org โบ news โบ multi-dimensional-arrays-in-python
Multi-Dimensional Arrays in Python โ Matrices Explained with Examples
December 11, 2025 - In this example, we create a 2-dimensional array using the np.array() function, and then use slicing to access a subarray that contains rows 0 through 1 and columns 1 through 2. We then modify the subarray by multiplying it by 2, and print the modified original array using the print() function. NumPy provides a wide range of mathematical and statistical functions that you can use to perform operations on multi-dimensional arrays efficiently.
Python Like You Mean It
pythonlikeyoumeanit.com โบ Module3_IntroducingNumpy โบ AccessingDataAlongMultipleDimensions.html
Accessing Data Along Multiple Dimensions in an Array โ Python Like You Mean It
You must now provide two indices, one for each axis (dimension), to uniquely specify an element in this 2D array; the first number specifies an index along axis-0, the second specifies an index along axis-1. The zero-based indexing schema that we reviewed earlier applies to each axis of the ND-array: -- axis-1 -> -2 -1 0 1 | +---+---+ | -3, 0 |93 | 95| | +---+---+ axis-0 -2, 1 |84 |100| | +---+---+ | -1, 2 |99 | 87| V +---+---+ Because grades has three entries along axis-0 and two entries along axis-1, it has a โshapeโ of (3, 2). ... Thus, if we want to access Bradโs (item-1 along axis-0) score for Exam 1 (item-0 along axis-1) we simply specify: # providing two numbers to access an element # in a 2D-array >>> grades[1, 0] # Brad's score on Exam 1 84 # negative indices work as with lists/tuples/strings >>> grades[-2, 0] # Brad's score on Exam 1 84
NumPy
numpy.org โบ devdocs โบ user โบ quickstart.html
NumPy quickstart โ NumPy v2.6.dev0 Manual
>>> a = np.arange(30) >>> b = a.reshape((2, -1, 3)) # -1 means "whatever is needed" >>> b.shape (2, 5, 3) >>> b array([[[ 0, 1, 2], [ 3, 4, 5], [ 6, 7, 8], [ 9, 10, 11], [12, 13, 14]], [[15, 16, 17], [18, 19, 20], [21, 22, 23], [24, 25, 26], [27, 28, 29]]]) How do we construct a 2D array from a list of equally-sized row vectors?
NumPy
numpy.org โบ doc โบ stable โบ user โบ absolute_beginners.html
NumPy: the absolute basics for beginners โ NumPy v2.5 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.
Python Data Science Handbook
jakevdp.github.io โบ PythonDataScienceHandbook โบ 02.02-the-basics-of-numpy-arrays.html
The Basics of NumPy Arrays | Python Data Science Handbook
Data manipulation in Python is nearly synonymous with NumPy array manipulation: even newer tools like Pandas (Chapter 3) are built around the NumPy array. This section will present several examples of using NumPy array manipulation to access data and subarrays, and to split, reshape, and join ...
Programiz
programiz.com โบ python-programming โบ numpy โบ ndarray-creation
NumPy N-D Array Creation (With Examples)
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)