>>> vec = np.asarray(l).reshape((1,-1)) 
>>> vec.shape
(1, 3)

I think is what you want ... maybe

Answer from Joran Beasley on Stack Overflow
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ numpy โ€บ numpy_array_shape.asp
NumPy Array Shape
NumPy arrays have an attribute called shape that returns a tuple with each index having the number of corresponding elements. ... The example above returns (2, 4), which means that the array has 2 dimensions, where the first dimension has 2 ...
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ numpy โ€บ numpy_array_reshape.asp
NumPy Array Reshaping
The shape of an array is the number of elements in each dimension. By reshaping we can add or remove dimensions or change number of elements in each dimension. Convert the following 1-D array with 12 elements into a 2-D array.
Discussions

python - Numpy - asarray of a list, dimension not automatically set in the vector - Stack Overflow
@user1506145 I don't believe this is what the OP wants... shape should be (3, 1) to make a column vector. ... I am really tired of reshaping every vector after np.asarray(). More on stackoverflow.com
๐ŸŒ stackoverflow.com
what's the difference between a numpy array with shape (x,) and (x, 1)?
import numpy as np arr = np.array([1, 2, 3, 4, 5]) print(arr.shape) # Output: (5,) arr = np.array([[1], [2], [3], [4], [5]]) print(arr.shape) # Output: (5, 1) arr = np.array([[1, 2, 3, 4, 5]]) print(arr.shape) # Output: (1, 5) More on reddit.com
๐ŸŒ r/learnpython
6
1
October 6, 2023
np.asarray - unexpected behaviour
When I try to do np.asarray of a list of arrays, it results in different behaviour depending on the dimensions of the arrays. When the list of arrays is of dimensions like (n,n) and (n,) it results in error. Reproducing code example: imp... More on github.com
๐ŸŒ github.com
10
August 7, 2019
python - Shape of an array in numpy.asarray - Stack Overflow
array_split can split the array into unequal sized arrays. Look at As in the 102 case. Look at the [distance ...] list (before applying np.asarray to it. It will contain many arrays. Check their shapes. If they are all the same it makes an array with a new first dimension. More on stackoverflow.com
๐ŸŒ stackoverflow.com
December 26, 2018
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ stable โ€บ reference โ€บ generated โ€บ numpy.ndarray.shape.html
numpy.ndarray.shape โ€” NumPy v2.4 Manual
Method similar to setting shape. ... Try it in your browser! >>> import numpy as np >>> x = np.array([1, 2, 3, 4]) >>> x.shape (4,) >>> y = np.zeros((2, 3, 4)) >>> y.shape (2, 3, 4) >>> y.shape = (3, 8) >>> y 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.]]) >>> y.shape = (3, 6) Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: cannot reshape array of size 24 into shape (3,6) >>> np.zeros((4,2))[::2].shape = (-1,) Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: Incompatible shape for in-place modification.
๐ŸŒ
NumPy
numpy.org โ€บ devdocs โ€บ reference โ€บ generated โ€บ numpy.shape.html
numpy.shape โ€” NumPy v2.5.dev0 Manual
The elements of the shape tuple give the lengths of the corresponding array dimensions. ... Equivalent array method. ... Try it in your browser! >>> import numpy as np >>> np.shape(np.eye(3)) (3, 3) >>> np.shape([[1, 3]]) (1, 2) >>> np.shape([0]) (1,) >>> np.shape(0) ()
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ what's the difference between a numpy array with shape (x,) and (x, 1)?
r/learnpython on Reddit: what's the difference between a numpy array with shape (x,) and (x, 1)?
October 6, 2023 -

hey, im doing an ai thing in school and my code didnt work as expected, and after 5 hours i found out i reshaped an array from (206,) to (206,1) and that made the results wrong. and from what i understand, the shape means the length of each dimension, and length is not 0 indexed so a size of 1 would be equal to just 1D no?

๐ŸŒ
Python Guides
pythonguides.com โ€บ python-numpy-shape
NumPy Shape And Array Dimensions In Python
May 16, 2025 - The shape attribute returns a tuple showing the size of each dimension. For a 1D array, itโ€™s simply the number of elements. For a 2D array, itโ€™s (rows, columns). For higher dimensions, it follows the same pattern. ... Letโ€™s use a more practical example.
Find elsewhere
๐ŸŒ
w3resource
w3resource.com โ€บ numpy โ€บ manipulation โ€บ asarray.php
NumPy: numpy.asarray() function - w3resource
March 24, 2023 - The numpy.asarray() function is used to convert n given input to an array. ... out [ndarray] Array interpretation of a. No copy is performed if the input is already an ndarray with matching dtype and order.
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ stable โ€บ reference โ€บ generated โ€บ numpy.asarray.html
numpy.asarray โ€” NumPy v2.4 Manual
>>> issubclass(np.recarray, np.ndarray) True >>> a = np.array([(1., 2), (3., 4)], dtype='f4,i4').view(np.recarray) >>> np.asarray(a) is a False >>> np.asanyarray(a) is a True
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ 2.2 โ€บ reference โ€บ generated โ€บ numpy.ndarray.shape.html
numpy.ndarray.shape โ€” NumPy v2.2 Manual
Method similar to setting shape. ... >>> import numpy as np >>> x = np.array([1, 2, 3, 4]) >>> x.shape (4,) >>> y = np.zeros((2, 3, 4)) >>> y.shape (2, 3, 4) >>> y.shape = (3, 8) >>> y 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.]]) >>> y.shape = (3, 6) Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: total size of new array must be unchanged >>> np.zeros((4,2))[::2].shape = (-1,) Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: Incompatible shape for in-place modification.
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ numpy โ€บ methods โ€บ shape
NumPy shape()
The shape() method returns the shape of an array i.e. the number of elements in each dimension. import numpy as np array = np.array([[0, 1], [2, 3]])
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ numpy-array-shape
NumPy Array Shape - GeeksforGeeks
July 15, 2025 - The shape of each array is printed, revealing their dimensions and sizes along each dimension. ... import numpy as npy # creating a 2-d array arr1 = npy.array([[1, 3, 5, 7], [2, 4, 6, 8]]) # creating a 3-d array arr2 = npy.array([[[1, 2], [3, ...
๐ŸŒ
GitHub
github.com โ€บ numpy โ€บ numpy โ€บ issues โ€บ 14221
np.asarray - unexpected behaviour ยท Issue #14221 ยท numpy/numpy
August 7, 2019 - import numpy as np a1 = [array([[-0.00491985, 0.00491965], [-0.00334969, 0.00334955], [-0.00136081, 0.00136076]], dtype=float32), array([-0.00104678, 0.00104674], dtype=float32)] a2 = [array([[-0.00334969, 0.00334955], [-0.00136081, 0.00136076]], dtype=float32), array([-0.00104678, 0.00104674], dtype=float32)] print(np.asarray(a1)) #works fine print(np.asarray(a2)) #throws error print(np.asarray([a.reshape(-1, 2) for a in a2])) #works fine
Author ย  deviganesan-coder
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ stable โ€บ reference โ€บ generated โ€บ numpy.shape.html
numpy.shape โ€” NumPy v2.4 Manual
The elements of the shape tuple give the lengths of the corresponding array dimensions. ... Equivalent array method. ... Try it in your browser! >>> import numpy as np >>> np.shape(np.eye(3)) (3, 3) >>> np.shape([[1, 3]]) (1, 2) >>> np.shape([0]) (1,) >>> np.shape(0) ()
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ numpy-asarray-in-python
numpy.asarray() in Python - GeeksforGeeks
November 12, 2021 - Let's understand with a simple ... is used when we want to return a contiguous array in memory (C order). Syntax : numpy.ascontiguousarray(arr, dtype=None) Parameters : arr : [array_like] Input data, in any form that can be converted to an array. This includes scalars, lists, lists of tuples, tuples, ... numpy.asarray_chkfinite() function is used when we want to convert the input to an array, checking for NaNs (Not A Number) or Infs(Infinities)....
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 53924928 โ€บ shape-of-an-array-in-numpy-asarray
python - Shape of an array in numpy.asarray - Stack Overflow
December 26, 2018 - QQ=np.asarray([distance.cdist(X,Y) for X in As for Y in Bs]) QQ.reshape(len(As),len(Bs) JJ=[np.concatenate((QQ[i,:]),axis=1) for i in range(len(As))] dist=np.concatenate((JJ[:]),axis=0) Gives exact same matrix with distance.cdist(A,B). But if Na=100, Nb=500 shape of previous array will be (100,10,50) prevent reshaping and concatenate operations.
๐ŸŒ
Note.nkmk.me
note.nkmk.me โ€บ home โ€บ python โ€บ numpy
NumPy: Get the dimensions, shape, and size of an array | note.nkmk.me
April 23, 2025 - You can get the number of dimensions, the shape (length of each dimension), and the size (total number of elements) of a NumPy array (numpy.ndarray) using the ndim, shape, and size attributes. The built-in len() function returns the size of the first dimension. ... Use the following one- to three-dimensional arrays as examples. import numpy as np a_1d = np.arange(3) print(a_1d) # [0 1 2] a_2d = np.arange(12).reshape((3, 4)) print(a_2d) # [[ 0 1 2 3] # [ 4 5 6 7] # [ 8 9 10 11]] a_3d = np.arange(24).reshape((2, 3, 4)) print(a_3d) # [[[ 0 1 2 3] # [ 4 5 6 7] # [ 8 9 10 11]] # # [[12 13 14 15] # [16 17 18 19] # [20 21 22 23]]]
๐ŸŒ
NumPy
numpy.org โ€บ devdocs โ€บ reference โ€บ generated โ€บ numpy.asarray.html
numpy.asarray โ€” NumPy v2.5.dev0 Manual
>>> issubclass(np.recarray, np.ndarray) True >>> a = np.array([(1., 2), (3., 4)], dtype='f4,i4').view(np.recarray) >>> np.asarray(a) is a False >>> np.asanyarray(a) is a True
๐ŸŒ
CS231n
cs231n.github.io โ€บ python-numpy-tutorial
Python Numpy Tutorial (with Jupyter and Colab)
The number of dimensions is the rank of the array; the shape of an array is a tuple of integers giving the size of the array along each dimension. We can initialize numpy arrays from nested Python lists, and access elements using square brackets: import numpy as np a = np.array([1, 2, 3]) # ...
๐ŸŒ
NumPy
numpy.org โ€บ devdocs โ€บ reference โ€บ generated โ€บ numpy.ndarray.shape.html
numpy.ndarray.shape โ€” NumPy v2.5.dev0 Manual
Method similar to setting shape. ... Try it in your browser! >>> import numpy as np >>> x = np.array([1, 2, 3, 4]) >>> x.shape (4,) >>> y = np.zeros((2, 3, 4)) >>> y.shape (2, 3, 4)