Pankaj(ADS)

Featured post

Python Codes for Electric Potential

Python Codes for Electric Potential Code:- import numpy as np import math import matplotlib.pyplot as plot ''' Calculating Elect...

Tuesday 29 June 2021

Python Program for Matrix Multiplication

0 comments

 Python Program for Matrix Multiplication

import numpy as np

import math


#------Python Program for Matix Multiplication-----#


# take a 2x3 matrix


X = [ [8, 6, 3],

      [6, 8, 4]]


# take a 3x3 matrix


Y = [ [7, 8, 1],

      [12, 9, 3],

      [2, 4, 5]]


result = [[0, 0, 0],

          [0, 0, 0]]


for  i in range(len(X)):

    for j in range(len(Y[0])):

        for k in range(len(Y)):

            result[i][j] += X[i][k] * Y[k][j]

for r in result:

    print(r)

OUTPUT

>>> 

=============== RESTART: D:/Desktop/Python(TUT)/MatrixMulti.py ===============

[134, 130, 41]

[146, 136, 50]

>>> 

No comments:

Post a Comment