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 ...
03:09
How to create a Numpy 2D Array in Python | Complete Guide | Examples ...
03:13
Python NumPy | 2D Arrays - YouTube
07:09
Python Basics for Data Science - Numpy 2D Arrays - YouTube
03:58
Creating Two Dimensional Array in NumPy | NumPy in Python Tutorial ...
12:13
Multidimensional array Numpy (1D, 2D, 3D array )| how to create ...
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
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:
Python Guides
pythonguides.com โบ python-numpy-2d-array
Create A 2D NumPy Array In Python (5 Simple Methods)
May 16, 2025 - The shape attribute tells us this is a 3ร3 array, and ndim confirms itโs a 2D array. This method is perfect when you already have your data structured in lists. ... When you need to initialize arrays with specific values, NumPy provides several convenient functions.
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.
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)
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:
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.
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.
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.
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)
Scaler
scaler.com โบ home โบ topics โบ matplotlib โบ how to visualize a 2d array?
How to Visualize a 2D Array? | Scaler Topics
June 5, 2024 - Matplotlib and Numpy provide the modules and functions to visualize a 2D array in Python. To visualize an array or list in matplotlib, we have to generate the data, which the NumPy library can do, and then plot the data using matplotlib. There are many functions by which we can add data to the array numpy.array(), numpy.arange(), numpy.linspace(), etc.
Sdsu
gawron.sdsu.edu โบ python_for_ss โบ course_core โบ book_draft โบ data โบ numpy.html
6.2. More on two-dimensional arrays โ python_for_ss 0.1.1 documentation
Boolean operations work more or less as expected on 2D arrays: import numpy as np y = np.arange(35).reshape(5,7) y>3
DataCamp
campus.datacamp.com โบ courses โบ intro-to-python-for-data-science โบ chapter-4-numpy
Your First 2D NumPy Array | Python
import numpy as np baseball = [[180, 78.4], [215, 102.7], [210, 98.5], [188, 75.2]] # Create a 2D numpy array from baseball: np_baseball # Print out the type of np_baseball # Print out the shape of np_baseball