[ Web Proxy ]
URL:
Viewing: https://numpy.org/doc/stable/reference/generated/numpy.ndarray.size.html [Back]  [Original]

numpy.ndarray.size — NumPy v2.5 Manual
Back to top
Search the docs ...:

numpy.ndarray.size#

attribute

ndarray.size#

Number of elements in the array.

Equal to np.prod(a.shape), i.e., the product of the arrays dimensions.

Notes

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.

Examples

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

Web Proxy Viewer  |  New URL  |  Original Page