Use a function such as np.zeros. No need to worry about the value it generates since there are no values in a 0 x 2 array:

arr = np.zeros((0, 2))
arr.shape

(0, 2)
Answer from busybear 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 ...
๐ŸŒ
NumPy
numpy.org โ€บ devdocs โ€บ reference โ€บ generated โ€บ numpy.ndarray.shape.html
numpy.ndarray.shape โ€” NumPy v2.5.dev0 Manual
Reshaping an array in-place will fail if a copy is required. ... Setting arr.shape is deprecated and may be removed in the future. Using ndarray.reshape is the preferred approach. ... Equivalent getter function. ... Function similar to setting shape. ... 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)
Discussions

python - How can I create a numpy array with shape (0, 2)? - Stack Overflow
The problem with nested lists is that the outer list will necessarily contain lists, and won't have a 0 size. Shape (0,2) means 0 'rows', 2 'columns'. ... Use a function such as np.zeros. No need to worry about the value it generates since there are no values in a 0 x 2 array: 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
arrays - what does numpy ndarray shape do? - Stack Overflow
Rank has a different meaning in matrix algebra. Regarding your question about comma: np.shape(arr) or arr.shape always return a tuple object. For 0D arrays, it's empty parens (), for 1D arrays it's a tuple with one element (elem1, ), for 2D arrays it's a tuple with two elements (elem1, elem2), ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
What is numpy actually used for?
If you donโ€™t work with anything that involves math then you probably never have to worry about numpy. A large population of python users though work with scientific computing, where itโ€™s math all the way down. Iโ€™m talking scalar-scalar operations (1 + 2) scalar-vector operations (2 + np.array([1, 2])) vector-vector operations (np.array([...]) + np.array([...])) vector-matrix (Ax = b) matrix-matrix (AB = C) vectorized math (np.sin(np.array([...])) other things like dot products, cross products, inverses of matrices, root finding and fitting algorithms, polynomial functions, basis functions, etc And so on. These are things I use numpy for every single day. More on reddit.com
๐ŸŒ r/learnpython
8
1
June 27, 2018
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ 2.2 โ€บ reference โ€บ generated โ€บ numpy.ndarray.shape.html
numpy.ndarray.shape โ€” NumPy v2.2 Manual
>>> 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. Use `.reshape()` to make a copy with the desired shape.
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ stable โ€บ reference โ€บ generated โ€บ numpy.ndarray.shape.html
numpy.ndarray.shape โ€” NumPy v2.4 Manual
>>> 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. Use `.reshape()` to make a copy with the desired shape.
๐ŸŒ
NumPy
numpy.org โ€บ devdocs โ€บ reference โ€บ generated โ€บ numpy.shape.html
numpy.shape โ€” NumPy v2.5.dev0 Manual
>>> a = np.array([(1, 2), (3, 4), (5, 6)], ... dtype=[('x', 'i4'), ('y', 'i4')]) >>> np.shape(a) (3,) >>> a.shape (3,)
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ stable โ€บ reference โ€บ generated โ€บ numpy.shape.html
numpy.shape โ€” NumPy v2.4 Manual
>>> a = np.array([(1, 2), (3, 4), (5, 6)], ... dtype=[('x', 'i4'), ('y', 'i4')]) >>> np.shape(a) (3,) >>> a.shape (3,)
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ numpy-array-shape
NumPy Array Shape - GeeksforGeeks
July 15, 2025 - Dimension is the number of indices ... array. In NumPy, we will use an attribute called shape which returns a tuple, the elements of the tuple give the lengths of the corresponding array dimensions....
Find elsewhere
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ stable โ€บ reference โ€บ routines.array-creation.html
Array creation routines โ€” NumPy v2.4 Manual
empty(shape[, dtype, order, device, like]) ยท Return a new array of given shape and type, without initializing entries
๐ŸŒ
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?

๐ŸŒ
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.
๐ŸŒ
Spark By {Examples}
sparkbyexamples.com โ€บ home โ€บ python โ€บ how to get numpy array shape?
How to Get NumPy Array Shape? - Spark By {Examples}
February 13, 2025 - Use ndarray.shape to get the shape of the NumPy array. This returns a tuple with each index having the number of corresponding elements. The below examples return (2,4) which means that the arr has 2 dimensions and each dimension has 4 elements ...
๐ŸŒ
Hyperskill
hyperskill.org โ€บ university โ€บ numpy โ€บ numpy-array-shape
NumPy Array Shape
September 4, 2024 - The array shape in NumPy defines the structure and organization of the array. It indicates the number of elements in each dimension and is accessed using the .shape attribute, which returns a tuple representing the array's dimensions. For example, a 2D array with shape (4, 3) has 4 rows and ...
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ 2.1 โ€บ reference โ€บ generated โ€บ numpy.ndarray.shape.html
numpy.ndarray.shape โ€” NumPy v2.1 Manual
>>> 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. Use `.reshape()` to make a copy with the desired shape.
๐ŸŒ
Python Guides
pythonguides.com โ€บ python-numpy-shape
NumPy Shape And Array Dimensions In Python
May 16, 2025 - Use reshape() to change the shape of a NumPy array without altering its data. import numpy as np # Create a 1D array with 12 elements sales_data = np.array([120, 145, 160, 178, 195, 210, 199, 187, 170, 155, 140, 130]) # Reshape into quarterly data for 3 years sales_reshaped = sales_data.reshape(3, ...
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ numpy โ€บ methods โ€บ shape
NumPy shape()
Created with over a decade of experience and thousands of feedback. ... Try Programiz PRO! ... Become a certified Python programmer. Try Programiz PRO! ... 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, ...
๐ŸŒ
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]) # ...
Top answer
1 of 4
82

yourarray.shape or np.shape() or np.ma.shape() returns the shape of your ndarray as a tuple; And you can get the (number of) dimensions of your array using yourarray.ndim or np.ndim(). (i.e. it gives the n of the ndarray since all arrays in NumPy are just n-dimensional arrays (shortly called as ndarrays))

For a 1D array, the shape would be (n,) where n is the number of elements in your array.

For a 2D array, the shape would be (n,m) where n is the number of rows and m is the number of columns in your array.

Please note that in 1D case, the shape would simply be (n, ) instead of what you said as either (1, n) or (n, 1) for row and column vectors respectively.

This is to follow the convention that:

For 1D array, return a shape tuple with only 1 element   (i.e. (n,))
For 2D array, return a shape tuple with only 2 elements (i.e. (n,m))
For 3D array, return a shape tuple with only 3 elements (i.e. (n,m,k))
For 4D array, return a shape tuple with only 4 elements (i.e. (n,m,k,j))

and so on.

Also, please see the example below to see how np.shape() or np.ma.shape() behaves with 1D arrays and scalars:

# sample array
In [10]: u = np.arange(10)

# get its shape
In [11]: np.shape(u)    # u.shape
Out[11]: (10,)

# get array dimension using `np.ndim`
In [12]: np.ndim(u)
Out[12]: 1

In [13]: np.shape(np.mean(u))
Out[13]: ()       # empty tuple (to indicate that a scalar is a 0D array).

# check using `numpy.ndim`
In [14]: np.ndim(np.mean(u))
Out[14]: 0

P.S.: So, the shape tuple is consistent with our understanding of dimensions of space, at least mathematically.

2 of 4
5

Unlike it's most popular commercial competitor, numpy pretty much from the outset is about "arbitrary-dimensional" arrays, that's why the core class is called ndarray. You can check the dimensionality of a numpy array using the .ndim property. The .shape property is a tuple of length .ndim containing the length of each dimensions. Currently, numpy can handle up to 32 dimensions:

a = np.ones(32*(1,))
a
# array([[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ 1.]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]])
a.shape
# (1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
a.ndim
# 32

If a numpy array happens to be 2d like your second example, then it's appropriate to think about it in terms of rows and columns. But a 1d array in numpy is truly 1d, no rows or columns.

If you want something like a row or column vector you can achieve this by creating a 2d array with one of its dimensions equal to 1.

a = np.array([[1,2,3]]) # a 'row vector'
b = np.array([[1],[2],[3]]) # a 'column vector'
# or if you don't want to type so many brackets:
b = np.array([[1,2,3]]).T
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ python-shape-method
Python shape() method - All you need to know! | DigitalOcean
August 4, 2022 - import numpy as np ar = np.array([[12,20] ,[13,15]]) print(ar) print("Shape of the array:") print(ar.shape) Output: [[12 20] [13 15]] Shape of the array: (2, 2) By this, we have come to the end of this topic. Feel free to comment below, in case you come across any questions. For more such posts related to Kubernetes, Stay tuned with us.
๐ŸŒ
Medium
medium.com โ€บ @techwithjulles โ€บ numpy-arrays-array-shape-and-dimensions-879b7592cf44
Numpy Arrays โ€” Array Shape and Dimensions | by TechwithJulles | Medium
November 16, 2023 - The shape of a NumPy array refers to the dimensions of the array. It tells you the number of rows and columns (or axes) of the array. To determine the shape of a NumPy array, you can use the .shape attribute.