How to Extract the Number of Rows and Columns in a Matrix
Hello, I would like to extract the number of rows and columns of a matrix individually. The shape command outputs the rows and columns together, but are there commands that will separately give the rows and separately give the columns? Thanks
len(M) will give you the number of rows of M. For columns I just use M.shape[1] myself, I don't know if there exists a shortcut. -=- Olivier Le 26 mars 2012 19:03, Stephanie Cooke <cooke.stephanie@gmail.com> a écrit :
Hello,
I would like to extract the number of rows and columns of a matrix individually. The shape command outputs the rows and columns together, but are there commands that will separately give the rows and separately give the columns?
Thanks _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
On 27.03.2012, at 1:26AM, Olivier Delalleau wrote:
len(M) will give you the number of rows of M. For columns I just use M.shape[1] myself, I don't know if there exists a shortcut.
You can use tuple unpacking, if that helps keeping your code conciser… nrow, ncol = M.shape Cheers, Derek
Le 26 mars 2012 19:03, Stephanie Cooke <cooke.stephanie@gmail.com> a écrit : Hello,
I would like to extract the number of rows and columns of a matrix individually. The shape command outputs the rows and columns together, but are there commands that will separately give the rows and separately give the columns?
Thanks
participants (3)
-
Derek Homeier -
Olivier Delalleau -
Stephanie Cooke