Reputation: 1151
I want to count easily the number of elements in a NumPy array, but I don't know a priori their dimensions. Is there a generic function that counts the number of elements in a numpy
array whatever its dimension is?
Upvotes: 4
Views: 6744
Reputation: 1125
numpy.ndarray.size returns a number of elements in the array
>>> x = np.zeros((3, 5, 2), dtype=np.complex128)
>>> x.size
30
Upvotes: 5