Home »
Python »
Linear Algebra using Python
Row numbers in a Matrix | Linear Algebra using Python
Linear Algebra using Python | Row numbers in a Matrix: Here, we are going to learn how to get row numbers in a matrix in Python?
Submitted by Anuj Singh, on May 20, 2020
Linear algebra
Linear algebra is the branch of mathematics concerning linear equations by using vector spaces and through matrices. Matrix is the key to linear algebra. All the linear algebra revolves around matrices. For many operations with a Matrix, we need to know about the number of rows in a matrix.
How to find row numbers in a matrix?
In Python, we can find it using two methods. One of the simplest methods we are going to see is just using the len(M) function. Python considers the length of a Matrix as the number of rows in it.
Rows also have a different interpretation as row space. So whenever we are asked to find the number of dimensions in the row space of a matrix, we can just put the inbuilt function len(M) in our code to answer such questions.
The following code shows how to call a whole row of a matrix.
Python Program for Row numbers in a Matrix
# Linear Algebra Learning Sequence
# Row numbers in a Matrix
import numpy as np
# Use of np.array() to define a matrix
V = np.array([[1,2,3],[2,3,5],[3,6,8],[323,623,823]])
print("--The Matrix-- \n",V)
#number of rows
num = len(V)
print("Number of rows in the Given Matrix : ", num)
Output
The output of the above program is:
--The Matrix--
[[ 1 2 3]
[ 2 3 5]
[ 3 6 8]
[323 623 823]]
Number of rows in the Given Matrix : 4