AlgebraOnMatrix Module in Python
Last Updated :
21 Apr, 2020
AlgebraOnMatrix module is that library of python which helps you to perform basic matrix algebra such as addition of two matrices, subtraction of two matrices, multiplication of two matrices, transpose of matrix .
Installing Library
This module does not come built-in with Python. You need to install it externally. To install this module type the below command in the terminal.
pip install AlgebraOnMatrix
Function of AlgebraOnMatrix
Matrix : It will transform our Two dimensional array into matrix .
Example :
from AlgebraOnMatrix import Matrix
arr = [[ 1 , 2 , 3 ], [ 4 , 5 , 6 , ], [ 7 , 8 , 9 ]]
a = Matrix(arr)
|
Operations on Matrix
- Addition of Matrices : Here we will add the matrix b with the matrix a where matrix b is given in 2d array .It will be done by function Matrix.addition(a, b) where a is a object which we have created and b is 2d array .
Example :
from AlgebraOnMatrix import Matrix
arr = [[ 1 , 2 , 3 ], [ 4 , 5 , 6 , ], [ 7 , 8 , 9 ]]
a = Matrix(arr)
b = [[ 1 , 2 , 3 ], [ 4 , 5 , 6 , ], [ 7 , 8 , 9 ]]
ans = Matrix.addition(a, b)
print (ans)
|
Output :
[[2, 4, 6], [8, 10, 12], [14, 16, 18]]
- Subtraction of Matrices :Here we will subtract the matrix b from the matrix a where matrix b is given in 2d array .It will be done by function Matrix.subtraction(a, b) where a is a object which we have created and b is 2d array .
Example :
from AlgebraOnMatrix import Matrix
arr = [[ 1 , 2 , 3 ], [ 4 , 5 , 6 , ], [ 7 , 8 , 9 ]]
a = Matrix(arr)
b = [[ 1 , 2 , 3 ], [ 4 , 5 , 6 , ], [ 7 , 8 , 9 ]]
ans = Matrix.subtraction(a, b)
print (ans)
|
Output :
[[0, 0, 0], [0, 0, 0], [0, 0, 0]]
- Multiplication of Matrices : Here we will multiply the matrix b with the matrix a where matrix b is given in 2d array .It will be done by function Matrix.multiplication(a, b) where a is a object which we have created and b is 2d array .
Example :
from AlgebraOnMatrix import Matrix
arr = [[ 1 , 2 , 3 ], [ 4 , 5 , 6 , ], [ 7 , 8 , 9 ]]
a = Matrix(arr)
b = [[ 1 , 2 , 3 ], [ 4 , 5 , 6 , ], [ 7 , 8 , 9 ]]
ans = Matrix.multiplication(a, b)
print (ans)
|
Output :
[[30, 36, 42], [66, 81, 96], [102, 126, 150]]
- Transpose of Matrix :Here we will transpose the matrix a.It will be done by function Matrix.transpose(a) where a is a object which we have created
Example :
from AlgebraOnMatrix import Matrix
arr = [[ 1 , 2 , 3 ], [ 4 , 5 , 6 , ], [ 7 , 8 , 9 ]]
a = Matrix(arr)
ans = Matrix.transpose(a)
print (ans)
|
Output :
[[1, 4, 7], [2, 5, 8], [3, 6, 9]]
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...