You can use the numpy size() function to get the total number of elements in a matrix.
Example:
>>> import numpy as np>>> a=np.asarray([[1,2,3],[4,5,6]])>>> aarray([[1, 2, 3], [4, 5, 6]])>>> np.size(a)6
>>> import numpy as np
>>> a=np.asarray([[1,2,3],[4,5,6]])
>>> a
array([[1, 2, 3],
[4, 5, 6]])
>>> np.size(a)
6
Another approach using shape:
>>> a.shape(2, 3)>>> s=a.shape>>> s[0]*s[1]6>>>
>>> a.shape
(2, 3)
>>> s=a.shape
>>> s[0]*s[1]
>>>