-
Notifications
You must be signed in to change notification settings - Fork 0
/
matrix.py
32 lines (28 loc) · 1.09 KB
/
matrix.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
'''
Universidad del Valle de Guatemala
Gráficas por computadora
Christopher García 20541
2do. ciclo 2022
'''
class Matrix(object):
def __init__(self, matrix = []):
self.matrix = matrix
def __matmul__(self, matrix_B):
res = [[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]
]
# multiply matrix
for i in range(len(self.matrix)):
for j in range(matrix_B.len()):
for k in range(matrix_B.len()):
if isinstance(matrix_B.matrix[0], int) or isinstance(matrix_B.matrix[0], float):
res[i][j] += self.matrix[i][k] * matrix_B.matrix[k]
elif isinstance(self.matrix[0], int) or isinstance(self.matrix[0], float):
res[i][j] += self.matrix[k] * matrix_B.matrix[k][j]
else:
res[i][j] += self.matrix[i][k] * matrix_B.matrix[k][j]
return Matrix(res)
def len(self):
return len(self.matrix)