Home »
Python »
Linear Algebra using Python
(i,j) Element from a Matrix | Linear Algebra using Python
Linear Algebra using Python | (i,j) Element from a Matrix: Here, we are going to learn how to find (i,j) Element from a Matrix in Python?
Submitted by Anuj Singh, on May 21, 2020
Prerequisite: Linear Algebra | Defining a Matrix
Linear algebra is the branch of mathematics concerning linear equations by using vector spaces and through matrices. In some of the problems, we need to use a particular element of the matrix. In the python code, we will first define a matrix and then we will call its (i,j) element.
i = row number
j = column number
Objective: A[i][j] ?
Python code for fidning (i,j) Element from a Matrix
# Linear Algebra Learning Sequence
# Defining a matrix using numpy
import numpy as np
# Use of np.array() to define a matrix
V = np.array([[1,2,3],[2,3,5],[3,6,8]])
print("--The Matrix-- \n",V)
# Finding the ith and jth entry in matrix
i = int(input("Enter i (row number) : "))
j = int(input("Enter j (column number) : "))
# Printing the V[i][j] element of the matrix
print("Component [",i,"] [",j,"] :", V[i-1][j-1])
Output:
--The Matrix--
[[1 2 3]
[2 3 5]
[3 6 8]]
Enter i (row number) : 3
Enter j (column number) : 2
Component [ 3 ] [ 2 ] : 6