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

Python – Matrix

Here we will discuss different ways how we can form a matrix using Python within this tutorial we will also discuss the various operation that can be performed on a matrix. we will also cover the external module Numpy to form a matrix and its operations in Python.

 

Similar Reads

What is the matrix?

A matrix is a collection of numbers arranged in a rectangular array in rows and columns. In the fields of engineering, physics, statistics, and graphics, matrices are widely used to express picture rotations and other types of transformations.The matrix is referred to as an m by n matrix, denoted by the symbol “m x n” if there are m rows and n columns....

Creating a simple matrix using Python

Method 1: Creating a matrix with a List of list...

Assigning Value in a matrix

...

Accessing Value in a matrix

...

Mathematical Operations with Matrix in Python

...

Transpose in matrix

Method 1: Assign value to an individual cell in Matrix...

Matrix using Numpy

...