Ahdee Ahdee - 1 year ago 87
Python Question

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

Hi apologies for the newbie question, but I'm wondering if someone can help me with two questions.
Example say I have this,


I have two questions.

  • How do I find total columns:

  • How do I find total rows:

thank you very much.

Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download