For numpy matrix in python
from numpy import matrix A = matrix([[1,2],[3,4]])
How can I find the length of the row (or column) of this matrix? Equivalently, how can I find out the number of rows or columns?
So far, the only solution I have found is:
len(A) len(A[:,1]) len(A[1,:])
which returns 2, 2, and 1, respectively. From this, I gathered that len() will return the number of rows, so I can always transpose, len(AT) , for the number of columns. However, this seems unsatisfactory and arbitrary, since when reading a line, len(A) does not immediately become obvious that this should return the number of lines. It really works differently than len([1,2]) for a python 2D array, as this will return 2.
So, is there a more intuitive way to find the size of the matrix, or is this the best I have?
python numpy matrix
Kyle Heuton Feb 13 '13 at 6:07 2013-02-13 06:07
source share