implements the matrix-vector multiplication. implements the matrix-scalar multiplication
(self, other)
| 325 | return self.__height |
| 326 | |
| 327 | def __mul__(self, other): |
| 328 | """ |
| 329 | implements the matrix-vector multiplication. |
| 330 | implements the matrix-scalar multiplication |
| 331 | """ |
| 332 | if isinstance(other, Vector): # vector-matrix |
| 333 | if other.size() == self.__width: |
| 334 | ans = zeroVector(self.__height) |
| 335 | for i in range(self.__height): |
| 336 | summe = 0 |
| 337 | for j in range(self.__width): |
| 338 | summe += other.component(j) * self.__matrix[i][j] |
| 339 | ans.changeComponent(i, summe) |
| 340 | summe = 0 |
| 341 | return ans |
| 342 | else: |
| 343 | raise Exception( |
| 344 | "vector must have the same size as the " |
| 345 | + "number of columns of the matrix!" |
| 346 | ) |
| 347 | elif isinstance(other, int) or isinstance(other, float): # matrix-scalar |
| 348 | matrix = [] |
| 349 | for i in range(self.__height): |
| 350 | row = [] |
| 351 | for j in range(self.__width): |
| 352 | row.append(self.__matrix[i][j] * other) |
| 353 | matrix.append(row) |
| 354 | return Matrix(matrix, self.__width, self.__height) |
| 355 | |
| 356 | def __add__(self, other): |
| 357 | """ |
nothing calls this directly
no test coverage detected