>>> add([[1,2],[3,4]],[[2,3],[4,5]]) [[3, 5], [7, 9]] >>> add([[1.2,2.4],[3,4]],[[2,3],[4,5]]) [[3.2, 5.4], [7, 9]] >>> add([[1, 2], [4, 5]], [[3, 7], [3, 4]], [[3, 5], [5, 7]]) [[7, 14], [12, 16]] >>> add([3], [4, 5]) Traceback (most recent call last): ...
(*matrix_s: list[list[int]])
| 8 | |
| 9 | |
| 10 | def add(*matrix_s: list[list[int]]) -> list[list[int]]: |
| 11 | """ |
| 12 | >>> add([[1,2],[3,4]],[[2,3],[4,5]]) |
| 13 | [[3, 5], [7, 9]] |
| 14 | >>> add([[1.2,2.4],[3,4]],[[2,3],[4,5]]) |
| 15 | [[3.2, 5.4], [7, 9]] |
| 16 | >>> add([[1, 2], [4, 5]], [[3, 7], [3, 4]], [[3, 5], [5, 7]]) |
| 17 | [[7, 14], [12, 16]] |
| 18 | >>> add([3], [4, 5]) |
| 19 | Traceback (most recent call last): |
| 20 | ... |
| 21 | TypeError: Expected a matrix, got int/list instead |
| 22 | """ |
| 23 | if all(_check_not_integer(m) for m in matrix_s): |
| 24 | for i in matrix_s[1:]: |
| 25 | _verify_matrix_sizes(matrix_s[0], i) |
| 26 | return [[sum(t) for t in zip(*m)] for m in zip(*matrix_s)] |
| 27 | raise TypeError("Expected a matrix, got int/list instead") |
| 28 | |
| 29 | |
| 30 | def subtract(matrix_a: list[list[int]], matrix_b: list[list[int]]) -> list[list[int]]: |
no test coverage detected