implements matrix subtraction.
(self, other: Matrix)
| 301 | raise Exception("matrix must have the same dimension!") |
| 302 | |
| 303 | def __sub__(self, other: Matrix) -> Matrix: |
| 304 | """ |
| 305 | implements matrix subtraction. |
| 306 | """ |
| 307 | if self.__width == other.width() and self.__height == other.height(): |
| 308 | matrix = [] |
| 309 | for i in range(self.__height): |
| 310 | row = [ |
| 311 | self.__matrix[i][j] - other.component(i, j) |
| 312 | for j in range(self.__width) |
| 313 | ] |
| 314 | matrix.append(row) |
| 315 | return Matrix(matrix, self.__width, self.__height) |
| 316 | else: |
| 317 | raise Exception("matrices must have the same dimension!") |
| 318 | |
| 319 | @overload |
| 320 | def __mul__(self, other: float) -> Matrix: ... |