numpy, how do I find total rows in a 2D array and total column in a 1D array

Getting number of rows and columns is as simple as:

>>> import numpy as np
>>> a=np.array([[1,2,3],[10,2,2]])
>>> num_rows, num_cols = a.shape
>>> print num_rows, num_cols
2 3

Leave a Comment