# Uppgift 3
+from matplotlib.pyplot import sca
+
+
def sum_of_ints2(value_list):
tot = 0
for inner in value_list:
def scalar_product(vec1, vec2):
prod = 0
- for row1 ,row2 in zip(vec1, vec2):
+ for row1, row2 in zip(vec1, vec2):
if isinstance(row1, list) and isinstance(row2, list):
for item1, item2 in zip(row1, row2):
prod += item1*item2
def matrix_square(matrix):
tot = [[] for _ in matrix]
- for idx, (row, col) in enumerate(zip(matrix, get_all_columns(matrix))):
- tot[idx].append(scalar_product(row, col))
+
+ cols = get_all_columns(matrix)
+
+ for i in range(len(matrix)):
+ for row in matrix:
+ tot[i].append(scalar_product(row, cols[i]))
+
return tot
+
print(matrix_square([[1, 2, 4],
- [3, 0, 6],
- [0, 5, 1]]
-))
\ No newline at end of file
+ [3, 0, 6],
+ [0, 5, 1]]
+ ))