>>> subtract([[1,2],[3,4]],[[2,3],[4,5]]) [[-1, -1], [-1, -1]] >>> subtract([[1,2.5],[3,4]],[[2,3],[4,5.5]]) [[-1, -0.5], [-1, -1.5]] >>> subtract([3], [4, 5]) Traceback (most recent call last): ... TypeError: Expected a matrix, got int/list instead
(matrix_a: list[list[int]], matrix_b: list[list[int]])
| 28 | |
| 29 | |
| 30 | def subtract(matrix_a: list[list[int]], matrix_b: list[list[int]]) -> list[list[int]]: |
| 31 | """ |
| 32 | >>> subtract([[1,2],[3,4]],[[2,3],[4,5]]) |
| 33 | [[-1, -1], [-1, -1]] |
| 34 | >>> subtract([[1,2.5],[3,4]],[[2,3],[4,5.5]]) |
| 35 | [[-1, -0.5], [-1, -1.5]] |
| 36 | >>> subtract([3], [4, 5]) |
| 37 | Traceback (most recent call last): |
| 38 | ... |
| 39 | TypeError: Expected a matrix, got int/list instead |
| 40 | """ |
| 41 | if ( |
| 42 | _check_not_integer(matrix_a) |
| 43 | and _check_not_integer(matrix_b) |
| 44 | and _verify_matrix_sizes(matrix_a, matrix_b) |
| 45 | ): |
| 46 | return [[i - j for i, j in zip(*m)] for m in zip(matrix_a, matrix_b)] |
| 47 | raise TypeError("Expected a matrix, got int/list instead") |
| 48 | |
| 49 | |
| 50 | def scalar_multiply(matrix: list[list[int]], n: float) -> list[list[float]]: |
nothing calls this directly
no test coverage detected