How do I find the length (or dimensions, size) of a numpy matrix in python? -
this question has reply here:
numpy array dimensions 2 answersfor numpy matrix in python
from numpy import matrix = matrix([[1,2],[3,4]])
how can find length of row (or column) of matrix? equivalently, how can know number of rows or columns?
so far, solution i've found is:
len(a) len(a[:,1]) len(a[1,:])
which returns 2, 2, , 1, respectively. i've gathered len()
homecoming number of rows, can transpose, len(a.t)
, number of columns. however, feels unsatisfying , arbitrary, when reading line len(a)
, isn't obvious should homecoming number of rows. works differently len([1,2])
2d python array, homecoming 2.
so, there more intuitive way find size of matrix, or best have?
shape
property of both numpy ndarray's , matrices.
a.shape
will homecoming tuple (m, n), m number of rows, , n number of columns.
in fact, numpy matrix
object built on top of ndarray
object, 1 of numpy's 2 fundamental objects (along universal function object), inherits ndarray
python matrix numpy
No comments:
Post a Comment