Accessing Value in a matrix
Method 1: Accessing Matrix values
Here, we are accessing elements of a Matrix by passing its row and column.
Python3
print ( "Matrix at 1 row and 3 column=" , X[ 0 ][ 2 ]) print ( "Matrix at 3 row and 3 column=" , X[ 2 ][ 2 ]) |
Output:
Matrix at 1 row and 3 column= 3 Matrix at 3 row and 3 column= 9
Method 2: Accessing Matrix values using negative indexing
Here, we are accessing elements of a Matrix by passing its row and column on negative indexing.
Python3
import numpy as np X = [[ 1 , 2 , 3 ], [ 4 , 5 , 6 ], [ 7 , 8 , 9 ]] print (X[ - 1 ][ - 2 ]) |
Output:
8