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 OverflowNumPy
numpy.org โบ devdocs โบ reference โบ generated โบ numpy.shape.html
numpy.shape โ NumPy v2.6.dev0 Manual
The elements of the shape tuple give the lengths of the corresponding array dimensions.
How to Draw Shape in Python For Beginners | Basic Python Tutorial ...
04:08
NumPy Array Shape - YouTube
07:52
How to Create NumPy Arrays in Python | Shape, Dimensions, Size ...
03:16
NumPy Array Shape Attribute Explained | Python NumPy Tutorial for ...
15:19
NumPy Tutorial #3: Reshaping Arrays - YouTube
04:55
Python NumPy|Understanding NumPy Arrays Shape |Python ...
Top answer 1 of 6
148
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
2 of 6
48
shape is a tuple that gives dimensions of the array..
Use with AI>>> c = arange(20).reshape(5,4)
>>> c
array([[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11],
[12, 13, 14, 15],
[16, 17, 18, 19]])
c.shape[0]
5
Gives the number of rows
Use with AIc.shape[1]
4
Gives number of columns
NumPy
numpy.org โบ doc โบ stable โบ reference โบ generated โบ numpy.shape.html
numpy.shape โ NumPy v2.5 Manual
Return the shape of an array.
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.
NumPy
numpy.org โบ doc โบ 2.1 โบ reference โบ generated โบ numpy.shape.html
numpy.shape โ NumPy v2.1 Manual
The elements of the shape tuple give the lengths of the corresponding array dimensions.
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?
Top answer 1 of 4
2
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)
2 of 4
2
Collections such as tuples, lists and 1d ndarrays are neither rows or columns (generally they display using whatever is most convenient) which si why: archive = ('hello', 'hello', 'hello') Can be rewritten as: archive = ('hello', 'hello', 'hello') And the two expressions are equivalent. For a ndarray the dimension of a vector is important for some applications: import numpy as np vector = np.array([0, 1, 2]) row = vector[np.newaxis, :] col = vector[:, np.newaxis] The vector: vector.shape vector.ndim Is a single dimension: (3, ) 1 The following are 2 dimensions: row.shape row.ndim (1, 3) 2 This is by definition 1 row by multiple (in this case 3) columns. col.shape cold.ndim (3, 1) 2 This is by definition multiple (in this case 3) rows by 1 column. For matrix multiplication for example, the inner dimensions need to match row @ col #(1, 3) @ (3, 1) And the array returned has the outer dimensions: array([[5]]) #(1) @ (1) If the other way is compared: col @ row #(3, 1) @ (1, 3) array([[0, 0, 0], [0, 1, 2], [0, 2, 4]]) #(3) @ (3)
Codecademy
codecademy.com โบ docs โบ python:numpy โบ ndarray โบ .shape
Python:NumPy | ndarray | .shape | Codecademy
October 30, 2025 - Returns a tuple representing the dimensions of an ndarray.
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
NumPy
numpy.org โบ doc โบ 2.3 โบ reference โบ generated โบ numpy.shape.html
numpy.shape โ NumPy v2.3 Manual
Return the shape of an array.
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