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