diff --git a/s1_a51.py b/s1_a51.py index 1325cbe..bea90cd 100644 --- a/s1_a51.py +++ b/s1_a51.py @@ -6,21 +6,24 @@ from scipy import sparse class Matrix: def __init__(self): - self.matrix = collections.defaultdict(dict) + self.__matrix = collections.defaultdict(dict) - def set(self, col, ro, value): + def set(self, column, row, value): if value == 0: - if self.matrix.get(col) and self.matrix.get(col).get(ro): - del self.matrix[col][ro] + if self.__matrix.get(column) and self.__matrix.get(column).get(row): + del self.__matrix[column][row] else: - self.matrix[col][ro] = value + self.__matrix[column][row] = value - def get(self, col, ro): - if self.matrix.get(col) and self.matrix.get(col).get(row): - return self.matrix[col][row] + def get(self, column, row): + if self.__matrix.get(column) and self.__matrix.get(column).get(row): + return self.__matrix[column][row] else: return 0 + def print(self): + print(self.__matrix) + if __name__ == "__main__": # Aufgabe 1b @@ -28,12 +31,12 @@ if __name__ == "__main__": [0, 0, 9, 0], [0, 7, 0, 0], [0, 0, 0, 0]] - mar = Matrix() - for row in range(len(input_matrix)): - for column in range(len(input_matrix[0])): - mar.set(row, column, input_matrix[row][column]) + sparse_matrix = Matrix() + for column in range(len(input_matrix)): + for row in range(len(input_matrix[0])): + sparse_matrix.set(column, row, input_matrix[row][column]) - print(mar.matrix) + sparse_matrix.print() # Aufgabe 1c # print("\nThe sparce matrix computed without numpy\n" + str(sparse_matrix)) diff --git a/s1_a53_6.py b/s1_a53_6.py index bd797ec..edc0f27 100644 --- a/s1_a53_6.py +++ b/s1_a53_6.py @@ -24,9 +24,7 @@ if __name__ == "__main__": for row in range(len(list_to_sort)): for next_row in range(row + 1, len(list_to_sort)): if list_to_sort[row][1] > list_to_sort[next_row][1]: - tmp = list_to_sort[row] - list_to_sort[row] = list_to_sort[next_row] - list_to_sort[next_row] = tmp + list_to_sort[row], list_to_sort[next_row] = list_to_sort[next_row], list_to_sort[row] print("The sorted list" + str(list_to_sort))