The shape attribute for numpy arrays returns the dimensions of the array. If Y has n rows and m columns, then Y.shape is (n,m). So Y.shape[0] is n.

Use with AIIn [46]: Y = np.arange(12).reshape(3,4)

In [47]: Y
Out[47]: 
array([[ 0,  1,  2,  3],
       [ 4,  5,  6,  7],
       [ 8,  9, 10, 11]])

In [48]: Y.shape
Out[48]: (3, 4)

In [49]: Y.shape[0]
Out[49]: 3
Answer from unutbu on Stack Overflow
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ python-shape-method
Python shape() method - All you need to know! | DigitalOcean
August 4, 2022 - Technical tutorials, Q&A, events โ€” This is an inclusive place where developers can find or lend support and discover new ways to contribute to the community.
๐ŸŒ
Python Guides
pythonguides.com โ€บ python-numpy-shape
NumPy Shape in Python: shape[0] and shape[1]
May 8, 2025 - What NumPy shape returns, what shape[0] and shape[1] count, why .shape() raises TypeError, and how shape differs from size, ndim and len.
๐ŸŒ
Pandas
pandas.pydata.org โ€บ docs โ€บ reference โ€บ api โ€บ pandas.DataFrame.shape.html
pandas.DataFrame.shape โ€” pandas 3.1.1 documentation
Unlike the len() method, which only returns the number of rows, shape provides both row and column counts, making it a more informative method for understanding dataset size.
Find elsewhere
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ numpy-array-shape
NumPy Array Shape - GeeksforGeeks
July 15, 2025 - The shape of an array can be defined as the number of elements in each dimension.
๐ŸŒ
Interactive Chaos
interactivechaos.com โ€บ en โ€บ python โ€บ function โ€บ ndarrayshape
ndarray.shape | Interactive Chaos
Python scenarios ยท Full name ยท ndarray.shape ยท Library ยท NumPy ยท Syntax ยท ndarray.shape ยท Description ยท The numpy.ndarray.shape attribute returns a tuple with the size of the array, but can also be used to resize it.
๐ŸŒ
NumPy
numpy.org โ€บ devdocs โ€บ reference โ€บ generated โ€บ numpy.ndarray.shape.html
numpy.ndarray.shape โ€” NumPy v2.6.dev0 Manual
The shape property is usually used to get the current shape of an array, but may also be used to reshape the array in-place by assigning a tuple of array dimensions to it. As with numpy.reshape, one of the new shape dimensions can be -1, in which case its value is inferred from the size of ...
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ 2.2 โ€บ reference โ€บ generated โ€บ numpy.ndarray.shape.html
numpy.ndarray.shape โ€” NumPy v2.2 Manual
The shape property is usually used to get the current shape of an array, but may also be used to reshape the array in-place by assigning a tuple of array dimensions to it. As with numpy.reshape, one of the new shape dimensions can be -1, in which case its value is inferred from the size of ...
๐ŸŒ
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?

๐ŸŒ
Pandas
pandas.pydata.org โ€บ pandas-docs โ€บ stable โ€บ reference โ€บ api โ€บ pandas.DataFrame.shape.html
pandas.DataFrame.shape โ€” pandas 3.1.0 documentation
Unlike the len() method, which only returns the number of rows, shape provides both row and column counts, making it a more informative method for understanding dataset size.
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ stable โ€บ reference โ€บ generated โ€บ numpy.ndarray.shape.html
numpy.ndarray.shape โ€” NumPy v2.5 Manual
The shape property is usually used to get the current shape of an array, but may also be used to reshape the array in-place by assigning a tuple of array dimensions to it. As with numpy.reshape, one of the new shape dimensions can be -1, in which case its value is inferred from the size of ...
๐ŸŒ
YouTube
youtube.com โ€บ codemy.com
Shape and Reshape Numpy Arrays - Numpy For Machine Learning 5 - YouTube
In this video we'll learn how to determine the shape of a Numpy Array and reshape a Numpy Array.You'll often need to determine the shape of a Numpy Array and...
Published: June 30, 2022
Views: 18K
๐ŸŒ
Medium
medium.com โ€บ @amit25173 โ€บ numpy-shape-in-python-6cfe7cb20084
numpy.shape in Python. If you think you need to spend $2,000โ€ฆ | by Amit Yadav | Medium
February 9, 2025 - Now, let me break this down for you. The shape attribute outputs (2, 3), which is a tuple. This tells you that your array has 2 rows and 3 columns.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ article โ€บ what-does-shape-do-in-for-i-in-range-y-shape-using-matplotlib
What does .shape[] do in "for i in range(Y.shape[0])" using Matplotlib?
The shape property is usually used to get the current shape of an array, but it may also be used to reshape the array in-place by assigning a tuple of array dimensions to it. Live Demo