Monday, December 30, 2024
Google search engine
HomeLanguagesAlgebraOnMatrix Module in Python

AlgebraOnMatrix Module in Python

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 :




# Importing Matrix function  
# From AlgebraOnMatrix Library  
from AlgebraOnMatrix import Matrix
  
arr =[[1, 2, 3], [4, 5, 6, ], [7, 8, 9]]
  
# Now we will transform our 2d array
# into the matrix and make an object
# of it 
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 :




    # Importing Matrix function  
    # From AlgebraOnMatrix Library  
    from AlgebraOnMatrix import Matrix
      
    arr =[[1, 2, 3], [4, 5, 6, ], [7, 8, 9]]
      
    # Now we will transform our 2d array 
    # into matrix and make an object of it 
    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 :




    # Importing Matrix function  
    # From AlgebraOnMatrix Library  
    from AlgebraOnMatrix import Matrix
      
    arr =[[1, 2, 3], [4, 5, 6, ], [7, 8, 9]]
      
    # Now we will transform our 2d array 
    # into matrix and make an object of it 
    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 :




    # Importing Matrix function  
    # From AlgebraOnMatrix Library  
    from AlgebraOnMatrix import Matrix
      
    arr =[[1, 2, 3], [4, 5, 6, ], [7, 8, 9]]
      
    # Now we will transform our 2d array 
    # into matrix and make an object of it 
    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 :




    # Importing Matrix function  
    # From AlgebraOnMatrix Library  
    from AlgebraOnMatrix import Matrix
      
    arr =[[1, 2, 3], [4, 5, 6, ], [7, 8, 9]]
      
    # Now we will transform our 2d array 
    # into matrix and make an object of it 
      
    a = Matrix(arr)
      
    ans = Matrix.transpose(a)
    print(ans)

    
    

    Output :

    [[1, 4, 7], [2, 5, 8], [3, 6, 9]]
    

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments