implements the matrix-addition.
(self, other)
| 354 | return Matrix(matrix, self.__width, self.__height) |
| 355 | |
| 356 | def __add__(self, other): |
| 357 | """ |
| 358 | implements the matrix-addition. |
| 359 | """ |
| 360 | if self.__width == other.width() and self.__height == other.height(): |
| 361 | matrix = [] |
| 362 | for i in range(self.__height): |
| 363 | row = [] |
| 364 | for j in range(self.__width): |
| 365 | row.append(self.__matrix[i][j] + other.component(i, j)) |
| 366 | matrix.append(row) |
| 367 | return Matrix(matrix, self.__width, self.__height) |
| 368 | else: |
| 369 | raise Exception("matrix must have the same dimension!") |
| 370 | |
| 371 | def __sub__(self, other): |
| 372 | """ |