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 OverflowDataCamp
campus.datacamp.com โบ courses โบ intro-to-python-for-data-science โบ chapter-4-numpy
2D NumPy Arrays | Python
Let's try to create one numpy array for all height and weight data of your family, like this. If you print out np_2d now, you'll see that it is a rectangular data structure: Each sublist in the list, corresponds to a row in the two dimensional numpy array. From np_2d.shape, you can see that ...
How to create '2D' Array in Numpy | Python NumPy Tutorial for ...
07:43
NumPy multidimensional arrays are easy! ๐ง - YouTube
08:16
2D Numpy Arrays for Data Science | Complete Python Tutorial - YouTube
05:14
Python Two Dimensional Numpy Arrays - YouTube
03:09
How to create a Numpy 2D Array in Python | Complete Guide | Examples ...
03:13
Python NumPy | 2D Arrays - YouTube
NumPy
numpy.org โบ doc โบ stable โบ reference โบ arrays.ndarray.html
The N-dimensional array (ndarray) โ NumPy v2.5 Manual
The array can be indexed using Python container-like syntax: >>> # The element of x in the *second* row, *third* column, namely, 6. >>> x[1, 2] 6 ยท For example slicing can produce views of the array:
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()
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
NumPy
numpy.org โบ devdocs โบ user โบ absolute_beginners.html
NumPy: the absolute basics for beginners โ NumPy v2.6.dev0 Manual
To add the rows or the columns in a 2D array, you would specify the axis. ... Learn more about basic operations here. There are times when you might want to carry out an operation between an array and a single number (also called an operation between a vector and a scalar) or between arrays of two different sizes. For example, your array (weโll call it โdataโ) might contain information about distance in miles but you want to convert the information to kilometers.
Call: +917738666252
Address: Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
NumPy
numpy.org โบ devdocs โบ user โบ quickstart.html
NumPy quickstart โ NumPy v2.6.dev0 Manual
The dots (...) represent as many colons as needed to produce a complete indexing tuple. For example, if x is an array with 5 axes, then ... >>> c = np.array([[[ 0, 1, 2], # a 3D array (two stacked 2D arrays) ... [ 10, 12, 13]], ... [[100, 101, 102], ...
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.
Programiz
programiz.com โบ python-programming โบ numpy โบ ndarray-creation
NumPy N-D Array Creation (With Examples)
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)
NumPy
numpy.org โบ devdocs โบ user โบ basics.creation.html
Array creation โ NumPy v2.6.dev0 Manual
For example: >>> import numpy as np >>> np.linspace(1., 4., 6) array([1. , 1.6, 2.2, 2.8, 3.4, 4. ]) The advantage of this creation function is that you guarantee the number of elements and the starting and end point. The previous arange(start, stop, step) will not include the value stop.
freeCodeCamp
freecodecamp.org โบ news โบ multi-dimensional-arrays-in-python
Multi-Dimensional Arrays in Python โ Matrices Explained with Examples
December 11, 2025 - To create a multi-dimensional array using NumPy, we can use the np.array() function and pass in a nested list of values as an argument. The outer list represents the rows of the array, and the inner lists represent the columns. Here is an example of how to create a 2-dimensional array using NumPy:
NumPy
numpy.org โบ doc โบ 2.5 โบ user โบ basics.creation.html
Array creation โ NumPy v2.5 Manual
For example: >>> import numpy as np >>> np.linspace(1., 4., 6) array([1. , 1.6, 2.2, 2.8, 3.4, 4. ]) The advantage of this creation function is that you guarantee the number of elements and the starting and end point. The previous arange(start, stop, step) will not include the value stop.
OpenGenus
iq.opengenus.org โบ 2d-array-in-numpy
2D Arrays in NumPy (Python)
October 28, 2022 - There are various built-in functions used to initialize an array Zeros Array zeros((r,c)) - It will return an array with all elements zeros with r number of rows and c number of columns.
Indian AI Production
indianaiproduction.com โบ home โบ blog โบ python numpy array โ create numpy ndarray (multidimensional array)
Python NumPy array - Create NumPy ndarray (multidimensional array)
June 12, 2019 - You can insert it while creating an array. import numpy as np # store student information in NumPy 2D array student_info = np.array([['id', 'name', 'percentage', 'pass or fail'], [101, 'Narendra', 80, 'pass'], [102, 'John', 75, 'pass'], [103, 'Abraham',33, 'fail'], [104, 'Oprah',52, 'pass'] ]) print(student_info)
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 ...
NumPy
numpy.org โบ doc โบ 2.2 โบ reference โบ arrays.ndarray.html
The N-dimensional array (ndarray) โ NumPy v2.2 Manual
The array can be indexed using Python container-like syntax: >>> # The element of x in the *second* row, *third* column, namely, 6. >>> x[1, 2] 6 ยท For example slicing can produce views of the array: