Answer to Question #287425 in Python for Rox

Question #287425

For every program, there should be a softcopy file containing (i) Algorithm/Flowchart, (ii)


Source Code, (iii) Output



Q.Write a program to calculate the product of two compatible matrices A and B.

1
Expert's answer
2022-01-17T00:34:12-0500
import numpy as np
A1 = [[2,3,4],[3,4,5],[5,6,7]]
A2 = [[1,2,3],[3,4,5],[5,6,7]]


A1 = np.array(A1)
A2 = np.array(A2)


C1 = A1.shape[1]
R1 = A1.shape[0]


C2 = A2.shape[1]
R2 = A2.shape[0]
print(A1.shape)
print(R1)
print(C1)


print(A2.shape)
print(R2)
print(C2)
if(C1 == R2):
    Prod = A1 * A2
    print("Product of two matrices:")
    print(Prod)
else:
    print("Matrices diumensions are invalid.")
    print("Columns in first matrix should be equal to rows in second matrix.")


Pseudocode:

Pseudocode

matrixMultiply(A1, A2):

Say dimension of A1 is (R1 x C1), dimension of A2 is (R2 x C2)

Begin

  if C1 is not same as R2, then exit

  otherwise define C matrix as (R1 x C2)

  for i in range 0 to R1 - 1, do

   for j in range 0 to C2 – 1, do

     for k in range 0 to R1, do

      C[i, j] = C[i, j] + (A[i, k] * A[k, j])

     done

   done

  done

End



Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS