import numpy as np class Matrix2x2: def __init__(self, a, b, c, d): # rader self._row1 = np.array([a, b]) self._row2 = np.array([c, d]) # kolonner self._column1 = np.array([a, c]) self._column2 = np.array([b, d]) def __str__(self): return str(self._row1) + "\n" + str(self._row2) # NOTE: I oppgaveteksten var det ikke spesifisert # hvilke matriser rad- og kolonnevektorene # skulle tilhøre. Det burde selvsagt stått # at den første faktoren er fra den første # matrisen og den siste fra den siste. def __mul__(self, other): a = np.dot(self._row1, other._column1) b = np.dot(self._row1, other._column2) c = np.dot(self._row2, other._column1) d = np.dot(self._row2, other._column2) return Matrix2x2(a, b, c, d) A = Matrix2x2(1, 2, 3, 4) I = Matrix2x2(1, 0, 0, 1) print() print(A) print() print(I) print() print(A*I) print()