-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathmatrices.py
More file actions
57 lines (41 loc) · 1.16 KB
/
matrices.py
File metadata and controls
57 lines (41 loc) · 1.16 KB
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
from numpy import empty
from numpy import zeros
import numpy as np
# m1rows
m = int(input("Enter the number of rows in matrix 1 : "))
# m1cols
n = int(input("Enter the number of cols in matrix 1 : "))
# m2rows
r = int(input("Enter the number of rows in matrix 2 : "))
# m2cols
s = int(input("Enter the number of cols in matrix 2 : "))
mat1 = empty([m, n])
mat2 = empty([r, s])
if n == r:
print("Matrices are compatible for multiplication")
result = zeros([m, s])
print("Please enter the Matrix 1:")
for x in range(0, m):
for y in range(0, n):
mat1[x][y] = input()
print("Please enter Matrix 2: ")
for a in range(0, r):
for b in range(0,s):
mat2[a][b] = input()
''' for i in range(0, m):
for j in range(0, s):
for k in range(0, r):
result[i][j] += mat1[i][k] * mat2[k][j]'''
result = np.dot(mat1,mat2)
print("Matrix 1")
for p in mat1:
print(p)
print("Matrix 2")
for p in mat2:
print(p)
print()
print("Product matrix :")
for p in result:
print(p)
else:
print("Matrices are not compatible for multiplication!")