(self, other: Matrix | float)
| 316 | ) |
| 317 | |
| 318 | def __mul__(self, other: Matrix | float) -> Matrix: |
| 319 | if isinstance(other, (int, float)): |
| 320 | return Matrix( |
| 321 | [[int(element * other) for element in row] for row in self.rows] |
| 322 | ) |
| 323 | elif isinstance(other, Matrix): |
| 324 | if self.num_columns != other.num_rows: |
| 325 | raise ValueError( |
| 326 | "The number of columns in the first matrix must " |
| 327 | "be equal to the number of rows in the second" |
| 328 | ) |
| 329 | return Matrix( |
| 330 | [ |
| 331 | [Matrix.dot_product(row, column) for column in other.columns()] |
| 332 | for row in self.rows |
| 333 | ] |
| 334 | ) |
| 335 | else: |
| 336 | raise TypeError( |
| 337 | "A Matrix can only be multiplied by an int, float, or another matrix" |
| 338 | ) |
| 339 | |
| 340 | def __pow__(self, other: int) -> Matrix: |
| 341 | if not isinstance(other, int): |
nothing calls this directly
no test coverage detected