From 998077d2c3e049d586edb8946e7cf1a23b9c2c4a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Nils=20Forss=C3=A9n?= Date: Tue, 8 Feb 2022 11:04:43 +0100 Subject: [PATCH] Changes --- laboration3/uppgift_2.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/laboration3/uppgift_2.py b/laboration3/uppgift_2.py index 2d83dd0..ae7af52 100644 --- a/laboration3/uppgift_2.py +++ b/laboration3/uppgift_2.py @@ -1,5 +1,8 @@ # Uppgift 3 +from matplotlib.pyplot import sca + + def sum_of_ints2(value_list): tot = 0 for inner in value_list: @@ -50,7 +53,7 @@ def get_all_columns(matrix): 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 @@ -61,11 +64,17 @@ def scalar_product(vec1, vec2): 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]] + )) -- 2.30.2