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 › devdocs › reference › generated › numpy.ndarray.size.html
numpy.ndarray.size — NumPy v2.6.dev0 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. This may not be the case with other methods of obtaining the same value (like the suggested np.prod(a.shape), which returns an instance of np.int_), and may be relevant if the value is used further in calculations that may overflow a fixed size integer type. ... Try it in your browser! >>> import numpy as np >>> x = np.zeros((3, 5, 2), dtype=np.complex128) >>> x.size 30 >>> np.prod(x.shape) 30
🌐
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.
🌐
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 ...
🌐
NumPy
numpy.org › doc › 2.2 › reference › generated › numpy.size.html
numpy.size — NumPy v2.2 Manual
ndarray.size · number of elements in array · Examples · >>> 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 › stable › reference › generated › numpy.ndarray.size.html
numpy.ndarray.size — NumPy v2.5 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. This may not be the case with other methods of obtaining the same value (like the suggested np.prod(a.shape), which returns an instance of np.int_), and may be relevant if the value is used further in calculations that may overflow a fixed size integer type. ... Try it in your browser! >>> import numpy as np >>> x = np.zeros((3, 5, 2), dtype=np.complex128) >>> x.size 30 >>> np.prod(x.shape) 30
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › python › find-the-memory-size-of-a-numpy-array
Find the memory size of a NumPy array - GeeksforGeeks
September 13, 2022 - itemsize: This attribute gives the memory size of one element of NumPy array in bytes.
🌐
Medium
medium.com › @techwithjulles › numpy-arrays-array-shape-and-dimensions-879b7592cf44
Numpy Arrays — Array Shape and Dimensions | by TechwithJulles | Medium
November 16, 2023 - As you can see, the .shape attribute can be used to determine the shape of arrays with different dimensions. Sometimes you may need to change the shape of a NumPy array. You can do this using the .reshape() method.
🌐
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. This may not be the case with other methods of obtaining the same value (like the suggested np.prod(a.shape), which returns an instance of np.int_), and may be relevant if the value is used further in calculations that may overflow a fixed size integer type. ... >>> import numpy as np >>> x = np.zeros((3, 5, 2), dtype=np.complex128) >>> x.size 30 >>> np.prod(x.shape) 30
🌐
W3Schools
w3schools.com › python › numpy › numpy_creating_arrays.asp
NumPy Creating Arrays
NumPy is used to work with arrays. The array object in NumPy is called ndarray.
🌐
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.array.html
numpy.array — NumPy v2.1 Manual
Specify the memory layout of the array. If object is not an array, the newly created array will be in C order (row major) unless ‘F’ is specified, in which case it will be in Fortran order (column major).
🌐
NumPy
numpy.org › doc › 2.4 › 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. This may not be the case with other methods of obtaining the same value (like the suggested np.prod(a.shape), which returns an instance of np.int_), and may be relevant if the value is used further in calculations that may overflow a fixed size integer type. ... Try it in your browser! >>> import numpy as np >>> x = np.zeros((3, 5, 2), dtype=np.complex128) >>> x.size 30 >>> np.prod(x.shape) 30
🌐
Python
docs.python.org › 3 › builtins › functions.html
Built-in Functions — Python 3.14.7 documentation
If it is an integer, the array will have that size and will be initialized with null bytes.
🌐
GeeksforGeeks
geeksforgeeks.org › machine learning › numpy-ndarray-size
NumPy ndarray.size() Method | Get Number of Elements in NumPy Array - GeeksforGeeks
July 12, 2025 - To find the number of elements in the NumPy array we use ndarray.size() method of the NumPy library in Python.
🌐
SciPy
docs.scipy.org › doc › numpy-1.6.0 › reference › generated › numpy.ndarray.size.html
numpy.ndarray.size — NumPy v1.6 Manual (DRAFT)
May 15, 2011 - NumPy Reference » · Array objects » · The N-dimensional array (ndarray) » · ndarray.size¶ · Number of elements in the array. Equivalent to np.prod(a.shape), i.e., the product of the array’s dimensions. Examples · >>> x = np.zeros((3, 5, 2), dtype=np.complex128) >>> x.size 30 >>> ...
🌐
CloudxLab
cloudxlab.com › assessment › displayslide › 2503 › numpy-arrays-attributes-of-a-numpy-array
NumPy - Arrays - Attributes of a NumPy Array | Automated hands-on| CloudxLab
NumPy array (ndarray class) is the most used construct of NumPy in Machine Learning and Deep Learning. Let us look into some important attributes of this NumPy
🌐
EDUCBA
educba.com › home › software development › software development tutorials › numpy tutorial › numpy size
NumPy size | Quick Glance on NumPy size with Examples
March 28, 2023 - The NumPy size is a function that is used to calculate the total elements or values for an axis in the given array, and when we provide an input array of different data structures that we can calculate their total number of values in its axis ...
Address: Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai