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
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
matrix.size according to the numpy docs returns the Number of elements in the array. Hope that helps.
len() of a numpy array in python - Stack Overflow
Pad zeros in middle of numpy array?
numpy: Trying to pad an array with zeros.
Convert numpy meshgrid to list of points and vice versa
Videos
What is the len of the equivalent nested list?
len([[2,3,1,0], [2,3,1,0], [3,2,1,1]])
With the more general concept of shape, numpy developers choose to implement __len__ as the first dimension. Python maps len(obj) onto obj.__len__.
X.shape returns a tuple, which does have a len - which is the number of dimensions, X.ndim. X.shape[i] selects the ith dimension (a straight forward application of tuple indexing).
Easy. Use .shape.
>>> nparray.shape
(5, 6) #Returns a tuple of array dimensions.