A.shape will return a tuple (m, n), where m is the number of rows, and n is the number of columns.

Answer from Anand S Kumar on Stack Overflow
🌐
MachineLearningMastery
machinelearningmastery.com › home › blog › how to set axis for rows and columns in numpy
How to Set Axis for Rows and Columns in NumPy - MachineLearningMastery.com
August 23, 2020 - For example, we can convert our list of lists matrix to a NumPy array via the asarray() function: We can print the array directly and expect to see two rows of numbers, where each row has three numbers or columns. We can summarize the dimensionality of an array by printing the “shape” property, which is a tuple, where the number of values in the tuple defines the number of dimensions, and the integer in each position defines the size of the dimension.
🌐
Indian AI Production
indianaiproduction.com › home › blog › python numpy shape – python numpy tutorial
Python NumPy shape - Python NumPy Tutorial
June 14, 2019 - The NumPy shape function helps to find the number of rows and columns of python NumPy array. The numpy.shape() function gives output in form of tuple.
🌐
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 - That’s exactly what numpy.shape does for your arrays! It’s a built-in attribute in NumPy that tells you the dimensions of an array as a tuple. The rows are the first number in the tuple, and the columns are the second.
🌐
NumPy
numpy.org › devdocs › user › absolute_beginners.html
NumPy: the absolute basics for beginners — NumPy v2.6.dev0 Manual
ndarray.shape will display a tuple of integers that indicate the number of elements stored along each dimension of the array. If, for example, you have a 2-D array with 2 rows and 3 columns, the shape of your array is (2, 3).
🌐
Plus2Net
plus2net.com › python › numpy-shape.php
Numpy shape to get row column and dimension of the array
numpy.shape(shape, dtype=None, order='C') Return tuple with details of the array. Shape() returns a tuple giving shape of the array. Number of rows , columns and dimension of the array.
🌐
Real Python
realpython.com › numpy-reshape
Using NumPy reshape() to Change the Shape of an Array – Real Python
July 20, 2026 - You reshape a NumPy array by passing a compatible shape to .reshape(), which rearranges the data without changing its values. A new shape is compatible only when its total number of elements matches the original array. reshape() can add or remove dimensions, so the new array doesn’t need the same number of dimensions as the original. The order parameter sets whether the data is read in row-major ("C") or column-major ("F") order.
🌐
Python Guides
pythonguides.com › python-numpy-shape
NumPy Shape in Python: shape[0] and shape[1]
May 8, 2025 - That is worth keeping straight when you move on to 3D arrays in NumPy. This is the part that sends people to search engines. For a 2D array, shape[0] is the number of rows and shape[1] is the number of columns:
Find elsewhere
🌐
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 - If you want to access either the number of rows or columns, you can retrieve each element of the tuple individually. ... You can also unpack the tuple and assign its elements to different variables. ... Use reshape() to convert the shape. See the following article for details. ... You can get the size, i.e., the total number of elements, of a NumPy array with the size attribute.
🌐
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 - Let’s dive into some practical uses of shape. ... Imagine you’re given a long list of numbers, but you need them organized neatly into rows and columns. That’s where reshape() comes in. It lets you rearrange the data while keeping all elements intact. ... import numpy as np # Reshaping a 1D array into a 2D array array = np.array([1, 2, 3, 4, 5, 6]) print("Original array:", array) print("Original shape:", array.shape) # Reshape the array to 2 rows and 3 columns reshaped_array = array.reshape(2, 3) print("\nReshaped array:\n", reshaped_array) print("New shape:", reshaped_array.shape)
🌐
GeeksforGeeks
geeksforgeeks.org › difference-between-numpy-array-shape-r-1-and-r
Difference between numpy.array shape (R, 1) and (R,) - GeeksforGeeks
April 28, 2025 - This shape tuple shows the number of columns in the 1-D array, i.e., the number of elements in that array. Since a 1-D array only has one row, the number of rows is not shown in the shape tuple.
🌐
Interactive Chaos
interactivechaos.com › en › python › function › ndarrayshape
ndarray.shape | Interactive Chaos
January 21, 2019 - In this case, the numpy array is formed from a list with two elements (two sublists), which is interpreted as two elements in the first dimension (rows), each of them formed by three other sublists, which is interpreted as three elements in the second dimension (columns), each one made up of three elements, which is interpreted as three elements in the third dimension (depth).
🌐
TutorialsPoint
tutorialspoint.com › article › finding-the-number-of-rows-and-columns-in-a-given-matrix-using-numpy
Finding the number of rows and columns in a given matrix using Numpy
March 25, 2026 - Shape: (2, 3) Total elements: 6 Number of dimensions: 2 ... import numpy as np matrix = np.array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]) print("Number of rows using len():", len(matrix)) print("Number of columns:", matrix.shape[1])
🌐
APXML
apxml.com › courses › linear-algebra-fundamentals-ml › chapter-2-numpy-numerical-computing › numpy-array-attributes-shape
NumPy Array Attributes and Shape
Notice how the elements fill the new shape row by row. The attempt to reshape into (3, 5) fails because ... Sometimes, you know the size of all but one dimension. You can use -1 as a placeholder in the reshape tuple, and NumPy will automatically calculate the correct size for that dimension based on the total number of elements. data = np.arange(12) # Array [0, 1, ..., 11] # Reshape to 2 rows, automatically calculating columns matrix_2_rows = data.reshape((2, -1)) print(f"Reshaped to (2, -1) -> shape {matrix_2_rows.shape}:\n{matrix_2_rows}") # Reshape to 4 columns, automatically calculating rows matrix_4_cols = data.reshape((-1, 4)) print(f"\nReshaped to (-1, 4) -> shape {matrix_4_cols.shape}:\n{matrix_4_cols}")
🌐
Sharp Sight
sharpsight.ai › blog › numpy-shape
The Numpy Shape Function, Explained - Sharp Sight
February 6, 2024 - In this case, the output of np.shape is a tuple with two numbers: (2,3). That’s the first number represents the number of rows (axis-0), and the second number represents the number of columns (axis-1). There are 2 rows and 3 columns, so the output of Numpy shape is (2,3).
🌐
TutorialsPoint
tutorialspoint.com › numpy › numpy_array_shape.htm
NumPy - Array Shape
The shape of a NumPy array is a tuple of integers. Each integer in the tuple represents the size of the array along a particular dimension or axis. For example, an array with shape (3, 4) has 3 rows and 4 columns.
🌐
Medium
medium.com › @monjurmbm404 › numpy-series-04-numpy-2d-arrays-matrix-basics-rows-columns-and-subarrays-27503a64b887
NumPy 2D Arrays: Matrix Basics, Rows, Columns and Subarrays | by Engr. Md Monjur Bakth Mazumder | Sep, 2026 | Medium
1 week ago - NumPy allows us to perform arithmetic operations directly on the entire array. ... NumPy performs these operations element by element. The shape attribute tells us the number of rows and columns.
🌐
Python Data Science Handbook
jakevdp.github.io › PythonDataScienceHandbook › 02.02-the-basics-of-numpy-arrays.html
The Basics of NumPy Arrays | Python Data Science Handbook
Another common reshaping pattern is the conversion of a one-dimensional array into a two-dimensional row or column matrix.