-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMatrixMultiplication_with_Text-to-Speech.py
57 lines (51 loc) · 1.6 KB
/
MatrixMultiplication_with_Text-to-Speech.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import numpy as np
from Audio_Utilities import *
s1 = "Defining a function for matrix-matrix multiplication..."
print(s1)
play_after_line(s1)
def MatrixMultiplication(matrix_a, matrix_b):
m,n = matrix_a.shape
n,p= matrix_b.shape
matrix_c = [[0 for j in range(p)] for i in range(m)]
for i in range(m):
for j in range(p):
for k in range(n):
matrix_c[i][j] += matrix_a[i][k]*matrix_b[k][j]
return np.array(matrix_c)
s2 = "Function for matrix-matrix multiplication defined!"
print(s2)
play_after_line(s2)
s3 = "Taking user inputs for the shapes of the matrices..."
print(s3)
play_after_line(s3)
m = int(input("Number of rows in the first matrix: "))
n = int(input("Number of rows in the second matrix: ")) # also equal to the no of cols in 1
p = int(input("Number of columns in the second matrix: "))
s4 = "Taking the elements of the first matrix from the user..."
print(s4)
play_after_line(s4)
A = np.zeros((m,n)).astype(int)
for i in range(m):
for j in range(n):
A[i][j] += int(input("A["+str(i)+"]["+str(j)+"]: "))
s5 = "Taking the elements of the second matrix from the user..."
print(s5)
play_after_line(s5)
B = np.zeros((n,p)).astype(int)
for i in range(n):
for j in range(p):
B[i][j] += int(input("B["+str(i)+"]["+str(j)+"]: "))
s6 = "Printing both the matrices..."
print(s6)
play_after_line(s6)
print("A is :\n", A)
print("B is :\n", B)
s7 = "Printing their product..."
print(s7)
play_after_line(s7)
C = MatrixMultiplication(A,B)
print("The product is: \n", C)
s8 = "The shape of their product is:"
print(s8)
play_after_line(s8)
print(C.shape)