According to the numpy docs, numpy.ndim(a) will returns:
The number of dimensions in a. Scalars are zero-dimensional
a = np.array(111)
b = np.array([1,2])
c = np.array([[1,2], [4,5]])
d = np.array([[1,2,3,], [4,5]])
print a.ndim, b.ndim, c.ndim, d.ndim
#outputs: 0 1 2 1
Here, the last array d is a variety of object dtype, so its dimension is as yet 1.
What you wanna use could be a.shape (or a.size for a one-dimensional exhibit/array):
print a.size, b.size
print c.size # == 4, which is the total number of elements in the array
Here, the method .shape will returns you a tuple, you ought to get your measurement utilizing :
print a.shape, b.shape, b.shape
() (2L,) 2
Wanna become a Python expert? Come and join the python certification course and get certified.
For more details, do check out the below video tutorial...