implements the matrix-addition.
(self,other)
| 274 | matrix = [[self.__matrix[i][j] * other for j in range(self.__width)] for i in range(self.__height)] |
| 275 | return Matrix(matrix,self.__width,self.__height) |
| 276 | def __add__(self,other): |
| 277 | """ |
| 278 | implements the matrix-addition. |
| 279 | """ |
| 280 | if (self.__width == other.width() and self.__height == other.height()): |
| 281 | matrix = [] |
| 282 | for i in range(self.__height): |
| 283 | row = [] |
| 284 | for j in range(self.__width): |
| 285 | row.append(self.__matrix[i][j] + other.component(i,j)) |
| 286 | matrix.append(row) |
| 287 | return Matrix(matrix,self.__width,self.__height) |
| 288 | else: |
| 289 | raise Exception("matrix must have the same dimension!") |
| 290 | def __sub__(self,other): |
| 291 | """ |
| 292 | implements the matrix-subtraction. |