Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

numpy

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

[[1,2,3],[10,2,2]]

I have two questions.

  • How do I find total columns:
  • How do I find total rows:

thank you very much. A

like image 859
Ahdee Avatar asked Sep 08 '13 21:09

Ahdee


People also ask

How do you find the number of rows in a 2D NumPy array?

In the NumPy with the help of shape() function, we can find the number of rows and columns. In this function, we pass a matrix and it will return row and column number of the matrix. Return: The number of rows and columns.


2 Answers

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 
like image 175
jabaldonedo Avatar answered Sep 18 '22 10:09

jabaldonedo


import numpy as np a = np.array([[1,2,3],[10,2,2]]) num_rows = np.shape(a)[0] num_columns = np.shape(a)[1] 
like image 38
Mohit Rai Avatar answered Sep 19 '22 10:09

Mohit Rai