The ndarray.size() method returns the number of elements in the NumPy array.
It works the same as np.prod(a.shape), i.e., the product of the dimensions of the array.
Example
Python3
import numpy as np arr = np.zeros((3, 4, 2), dtype = np.complex128) gfg = arr.size print (gfg) |
Output :
24
Syntax
Syntax: numpy.ndarray.size(arr)
Parameters
- arr : [array_like] Input array.
Return : [int] The number of elements in the array.
How to Find Number of Elements in NumPy Array
To find the number of elements in the NumPy array we use ndarray.size() method of the NumPy library in Python.
Let us understand it better with an example:
Python3
import numpy as geek arr = geek.zeros((3, 4, 2), dtype = geek.complex128) gfg = geek.prod(arr.shape) print (gfg) |
Output :
24
Share your thoughts in the comments

