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.

In [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
🌐
DeepLearning.AI
community.deeplearning.ai › course q&a › machine learning specialization › advanced learning algorithms
Difference between .shape[0] and .shape[1] - Advanced Learning Algorithms - DeepLearning.AI
August 27, 2022 - Hi, In the course, i find sometimes the code is written as m=X.shape[0] and n=w.shape[1]. Can you tell me the difference between these 2 functions, .shape[0] and .shape[1], though both returns the number of columns in a…
🌐
NumPy
numpy.org › devdocs › reference › generated › numpy.shape.html
numpy.shape — NumPy v2.5.dev0 Manual
len(a) is equivalent to np.shape(a)[0] for N-D arrays with N>=1. ndarray.shape · Equivalent array method. Examples · 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) () >>> a = np.array([(1, 2), (3, 4), (5, 6)], ...
🌐
W3Schools
w3schools.com › python › numpy › numpy_array_shape.asp
NumPy Array Shape
W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.
🌐
Medium
medium.com › @heyamit10 › understanding-pandas-shape-ba74dadf8387
Understanding pandas.shape
March 6, 2025 - rows = df.shape[0] # Number of rows columns = df.shape[1] # Number of columns print("Rows:", rows) print("Columns:", columns)
🌐
Coding Blocks
discuss.codingblocks.com › machine learning
What does X.shape[0] mean? - Machine Learning - Coding Blocks Discussion Forum
October 17, 2019 - Did not understand how this gives number of training examples? And shouldn’t the syntax should be X.shape only? Why [0] is there?
Find elsewhere
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-shape-method
Python shape() method - All you need to know! | DigitalOcean
August 4, 2022 - Hello, readers! This article talks about the Python shape() method and its variants in programming with examples.
🌐
GeeksforGeeks
geeksforgeeks.org › numpy › numpy-zeros-python
numpy.zeros() in Python - GeeksforGeeks
January 24, 2025 - numpy.zeros() function creates a new array of specified shapes and types, filled with zeros. It is beneficial when you need a placeholder array to initialize variables or store intermediate results.
🌐
scikit-learn
scikit-learn.org › stable › modules › preprocessing.html
7.3. Preprocessing data — scikit-learn 1.8.0 documentation
The sklearn.preprocessing package provides several common utility functions and transformer classes to change raw feature vectors into a representation that is more suitable for the downstream esti...
🌐
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 - How to use len() in Python · For a numpy.ndarray, len() returns the size of the first dimension, which is equivalent to shape[0]. It is also equal to size only for one-dimensional arrays. print(len(a_1d)) # 3 print(a_1d.shape[0]) # 3 print(a_1d.size) # 3 print(len(a_2d)) # 3 print(a_2d.shape[0]) # 3 print(len(a_3d)) # 2 print(a_3d.shape[0]) # 2 ·
🌐
Medium
medium.com › @amit25173 › understanding-numpy-shape-6fbb6b83891e
Understanding numpy.shape. If you think you need to spend $2,000… | by Amit Yadav | Medium
February 9, 2025 - # A 2D array array = np.array([[1, 2, 3], [4, 5, 6]]) # Print the number of rows and columns print("Number of rows:", array.shape[0]) print("Number of columns:", array.shape[1]) # Iterating through rows for i in range(array.shape[0]): print("Row", i + 1, ":", array[i]) Output: Number of rows: 2 Number of columns: 3 Row 1 : [1 2 3] Row 2 : [4 5 6] Did you notice how I used array.shape[0] and array.shape[1]? These let you dynamically adapt your loops to any array size.
🌐
Qiita
qiita.com › python
【備忘録】shape[0], shape[1], shape[2]の中身 #Python - Qiita
August 25, 2020 - Python · OpenCV · 備忘録 · Last updated at 2020-08-25Posted at 2020-08-05 · a.shape[0]はaの行(row)の数、a.shape[1]は列(col)の数、a.shape[2]はチャンネル数 · 15 · Go to list of users who liked · 6 · comment0 · Go to list of comments ·
🌐
AskPython
askpython.com › home › python shape function: find dimensions of arrays and dataframes
Python Shape Function: Find Dimensions of Arrays and DataFrames - AskPython
April 8, 2023 - To use the shape function in Python, first import the Pandas library with import pandas as pd and create a DataFrame using df = pd.DataFrame(data). Then, obtain the dimensions as a tuple using dimensions = df.shape. For NumPy arrays, import the NumPy library using import numpy as np, create an array with arr = np.array(data), and get the dimensions with dimensions = arr.shape.
🌐
Python documentation
docs.python.org › 3 › library › stdtypes.html
Built-in Types — Python 3.14.3 documentation
February 25, 2026 - Python defines pow(0, 0) and 0 ** 0 to be 1, as is common for programming languages.
🌐
Python
docs.python.org › 3 › library › turtle.html
turtle — Turtle graphics
February 23, 2026 - Data structure modeling shapes. The pair (type_, data) must follow this specification: ... >>> poly = ((0,0),(10,-5),(0,10),(-10,-5)) >>> s = Shape("compound") >>> s.addcomponent(poly, "red", "blue") >>> # ...
🌐
Wikipedia
en.wikipedia.org › wiki › Sigmoid_function
Sigmoid function - Wikipedia
January 19, 2026 - A sigmoid function is convex for values less than a particular point, and it is concave for values greater than that point: in many of the examples here, that point is 0.
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.shape.html
pandas.DataFrame.shape — pandas 3.0.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.