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 OverflowNumPy
numpy.org โบ doc โบ stable โบ user โบ basics.creation.html
Array creation โ NumPy v2.5 Manual
vander(x, n) defines a Vandermonde matrix as a 2D NumPy array. Each column of the Vandermonde matrix is a decreasing power of the input 1D array or list or tuple, x where the highest polynomial order is n-1. This array creation routine is helpful in generating linear least squares models, as such:
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()
How to create a two-dimensional array using NumPy? - Python - Data Science Dojo Discussions
I have comprehended multiple methods ... using NumPy. Now, I aspire to master methods that help in developing a two-dimensional array. For this purpose, I have found one method that aids me in defining a 2D array. Here is the code below: Apart from the above method, if you know any other method that provides me the functionality of creating a two-dimensional ... More on discuss.datasciencedojo.com
How to create a 2D Numpy array in Python? - Programming Language - Discussion Forum | Board Infinity
Array in Numpy is a table of elements (usually numbers), all of the same type, indexed by a tuple of positive integers. In Numpy, number of dimensions of the array is called rank of the array.A tuple of integers giving the size of the array along each dimension is known as shape of the array. More on discuss.boardinfinity.com
Making a 2D array
[list1, list2]? Python doesn't have the concept of "2D lists" natively - they're just lists that contain lists. More on reddit.com
Split a 2d NumPy array into 2 separate 2d arrays based on a column value
np.split isn't doing what you think it's doing and you don't need it for this. To split an original array x into two subarrays a and b the way you want, you can simply do this: x = np.array([[1, 2, 4], [1, 4, 4], [2, 2, 4], [2, 5, 9]]) a = x[x[:, 0] == 1] b = x[x[:, 0] == 2] More on reddit.com
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 โบ 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.
Data Science Dojo
discuss.datasciencedojo.com โบ python
How to create a two-dimensional array using NumPy? - Python - Data Science Dojo Discussions
May 15, 2023 - I have comprehended multiple methods ... using NumPy. Now, I aspire to master methods that help in developing a two-dimensional array. For this purpose, I have found one method that aids me in defining a 2D array. Here is the code below: Apart from the above method, if you know any other method that provides me the functionality of creating a two-dimensional ...
Board Infinity
discuss.boardinfinity.com โบ programming language
How to create a 2D Numpy array in Python? - Programming Language - Discussion Forum | Board Infinity
September 27, 2022 - Array in Numpy is a table of elements (usually numbers), all of the same type, indexed by a tuple of positive integers. In Numpy, number of dimensions of the array is called rank of the array.A tuple of integers giving the size of the array along each dimension is known as shape of the array.
NumPy
numpy.org โบ doc โบ 2.4 โบ reference โบ arrays.ndarray.html
The N-dimensional array (ndarray) โ NumPy v2.4 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.
NumPy
numpy.org โบ doc โบ 2.3 โบ user โบ absolute_beginners.html
NumPy: the absolute basics for beginners โ NumPy v2.3 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 โบ stable โบ reference โบ generated โบ numpy.array.html
numpy.array โ NumPy v2.5 Manual
Specifies the minimum number of dimensions that the resulting array should have. Ones will be prepended to the shape as needed to meet this requirement. ... Specifies the maximum number of dimensions to create when inferring shape from nested sequences. By default (ndmax=0), NumPy recurses through all nesting levels (up to the compile-time constant NPY_MAXDIMS).
Reddit
reddit.com โบ r/learnpython โบ making a 2d array
r/learnpython on Reddit: Making a 2D array
April 22, 2019 -
Hey all,
I have two lists of dimension 1xn. I want to make them into an array of size 2xn. If i use the extend command it makes them into a list of size 1x2n..
How can I do this?
Top answer 1 of 2
2
[list1, list2]? Python doesn't have the concept of "2D lists" natively - they're just lists that contain lists.
2 of 2
1
Can you give more information about task? Is the size of lists the same? What kind of data in lists? Btw, You can use K900_ 's variant or probably numpy: >>> import numpy as np >>> a = [1, 2, 3] >>> b = [4, 5, 6] >>> arr = np.array([a, b]) >>> print(arr) [[1 2 3] [4 5 6]] >>> print(arr.shape) (2, 3) >>> print(arr[1][2]) 6
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
GeeksforGeeks
geeksforgeeks.org โบ numpy โบ python-numpy
Python NumPy - GeeksforGeeks
NumPy arrays are created using the np.array() function.
Published: June 12, 2026
NumPy
numpy.org โบ devdocs โบ user โบ basics.creation.html
Array creation โ NumPy v2.6.dev0 Manual
vander(x, n) defines a Vandermonde matrix as a 2D NumPy array. Each column of the Vandermonde matrix is a decreasing power of the input 1D array or list or tuple, x where the highest polynomial order is n-1. This array creation routine is helpful in generating linear least squares models, as such: