shape is a property of both numpy ndarray's and matrices.

A.shape

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

In fact, the numpy matrix object is built on top of the ndarray object, one of numpy's two fundamental objects (along with a universal function object), so it inherits from ndarray

Answer from Kyle Heuton on Stack Overflow
🌐
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.ndarray.size.html
numpy.ndarray.size — NumPy v2.1 Manual
Equal to np.prod(a.shape), i.e., the product of the array’s dimensions. ... a.size returns a standard arbitrary precision Python integer.
Discussions

len() of a numpy array in python - Stack Overflow
Why is there no argument for len() about which axis I want the length of in multidimensional arrays? This is alarming. Is there an alternative? ... With the more general concept of shape, numpy developers choose to implement __len__ as the first dimension. Python maps len(obj) onto obj.__len__. More on stackoverflow.com
🌐 stackoverflow.com
Pad zeros in middle of numpy array?
Every Nth row, set every cell to zero whose index (plus one) is divisible by N. More on reddit.com
🌐 r/Python
8
2
April 13, 2019
numpy: Trying to pad an array with zeros.
I would like to learn NumPy but don't know if I need to. ... We let type hints completely ruin the readability of python.. More on reddit.com
🌐 r/learnpython
1
3
April 19, 2013
Convert numpy meshgrid to list of points and vice versa
A simpler way of getting the grid of points is to reshape the grid by keeping the topmost axis (of size 2) and flattening the rest, then transposing it. grid.reshape(2,-1).T Here, -1 means that it is an unknown dimension and we want numpy to figure it out. This loses information about the dimensions, so to reverse it, you transpose it back, then reshape it to the original dimensions which you have to specify explicitly. More on reddit.com
🌐 r/learnpython
1
2
March 12, 2020
🌐
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. The bui ...
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › how to get numpy array length
How to Get NumPy Array Length - Spark By {Examples}
March 27, 2024 - You can find the length of a NumPy array using the built-in len() function in Python, which returns the number of elements in the first dimension of the array.
🌐
Pierian Training
pieriantraining.com › home › python numpy tutorial: get length of array in python
Python NumPy Tutorial: Get Length of Array in Python - Pierian Training
April 27, 2023 - The easiest and most straightforward way to get the length of a NumPy array is by using the built-in Python function `len()`. This function returns the number of elements in an object, including the elements in a NumPy array.
🌐
Udacity
udacity.com › blog › 2021 › 10 › how-to-calculate-the-length-of-an-array-in-python.html
How to calculate the length of an array in Python? | Udacity
October 20, 2021 - When using a list or NumPy array ... code. Python makes it easy to calculate the length of any list or array, thanks to the len() method....
🌐
Scaler
scaler.com › home › topics › length of array in python
Length of array in Python - Scaler Topics
May 25, 2022 - We can use Python's len() function to find the length of an array. For a Numpy array also, we can use the len() function to find the array's length in Python.
Find elsewhere
🌐
Delft Stack
delftstack.com › home › howto › numpy › numpy array length
How to Get NumPy Array Length | Delft Stack
March 11, 2025 - Learn how to get the length of a NumPy array in Python with two primary methods: numpy.size and numpy.shape. This guide explains each method in detail, providing clear examples and insights into their use. Enhance your data analysis skills and streamline your coding process with these essential ...
🌐
Flexiple
flexiple.com › python › length-of-array-python
Python Array Length - How to Calculate the Length of an Array in Python - Flexiple - Flexiple
April 11, 2022 - To find the length of a Numpy array, you can use the shape attribute or the len() function for one-dimensional arrays.
🌐
GeeksforGeeks
geeksforgeeks.org › python › numpy-size-function-python
Numpy size() function | Python - GeeksforGeeks
July 12, 2025 - Here we create a 2D array arr with 2 rows and 4 columns and use np.size() function which will return the total number of elements in the array. ... Here 0 is used to denote the axis as rows and 1 is used to denote axis as columns.
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.ndarray.size.html
numpy.ndarray.size — NumPy v2.4 Manual
Equal to np.prod(a.shape), i.e., the product of the array’s dimensions. ... a.size returns a standard arbitrary precision Python integer.
🌐
IONOS
ionos.com › digital guide › websites › web development › python array length
How to find out the length of a Python array
July 11, 2023 - First, we’ll create the same array as in the example above, which contains the numbers 0 to 5 and saves the variable l as length. Then, we’ll create an array that is made up of three unique arrays and save this with the variable s. import numpy as np # onedimensional Array a = np.array([0,1,2,3,4,5]) l = a.size # multidimensional Array m = np.array([[0,1,2], [3,4,5], [6,7,8], [9,10,11]]) s = m.sizepython
🌐
Leapcell
leapcell.io › blog › understanding-array-length-in-python
Understanding Array Length in Python | Leapcell
July 25, 2025 - Use len() to get the length of Python lists and arrays. NumPy arrays offer .size for total element count.
🌐
GeeksforGeeks
geeksforgeeks.org › python-array-length
Python Array length - GeeksforGeeks
May 8, 2025 - In numpy, if the underlying data type of the given object is string then the dtype of object is the length of the longest string in the array. This is so because we cannot create variable l ... The length of a list means the number of elements ...
🌐
TutorialsPoint
tutorialspoint.com › find-the-size-of-numpy-array
Find the size of numpy Array
August 23, 2023 - Length of the array: 5 Space occupied by one element: 8 bytes Total memory occupied by the element: 40 bytes · In the following example, we compute the same information for a multi-dimensional numpy array.
🌐
Finxter
blog.finxter.com › home › learn python blog › 5 best ways to determine the length of a numpy array
5 Best Ways to Determine the Length of a NumPy Array - Be on the Right Side of Change
February 20, 2024 - It then uses the shape attribute ... prints them out. The built-in Python function len() returns the size of the first dimension (length of the outermost array) of a NumPy array....
🌐
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.ma.size.html
numpy.ma.size — NumPy v2.1 Manual
Number of elements along the specified axis. ... >>> import numpy as np >>> a = np.array([[1,2,3],[4,5,6]]) >>> np.size(a) 6 >>> np.size(a,1) 3 >>> np.size(a,0) 2
🌐
NumPy
numpy.org › doc › 2.2 › reference › generated › numpy.ndarray.size.html
numpy.ndarray.size — NumPy v2.2 Manual
Equal to np.prod(a.shape), i.e., the product of the array’s dimensions. ... a.size returns a standard arbitrary precision Python integer.
🌐
NumPy
numpy.org › devdocs › user › quickstart.html
NumPy quickstart — NumPy v2.5.dev0 Manual
This is a tuple of integers indicating the size of the array in each dimension. For a matrix with n rows and m columns, shape will be (n,m). The length of the shape tuple is therefore the number of axes, ndim. ... an object describing the type of the elements in the array. One can create or specify dtype’s using standard Python types.