Return self + another. Example: >>> a = Matrix(2, 1, -4) >>> b = Matrix(2, 1, 3) >>> a+b Matrix consist of 2 rows and 1 columns [-1] [-1]
(self, another: Matrix)
| 100 | self.array[loc[0]][loc[1]] = value |
| 101 | |
| 102 | def __add__(self, another: Matrix) -> Matrix: |
| 103 | """ |
| 104 | <method Matrix.__add__> |
| 105 | Return self + another. |
| 106 | Example: |
| 107 | >>> a = Matrix(2, 1, -4) |
| 108 | >>> b = Matrix(2, 1, 3) |
| 109 | >>> a+b |
| 110 | Matrix consist of 2 rows and 1 columns |
| 111 | [-1] |
| 112 | [-1] |
| 113 | """ |
| 114 | |
| 115 | # Validation |
| 116 | assert isinstance(another, Matrix) |
| 117 | assert self.row == another.row |
| 118 | assert self.column == another.column |
| 119 | |
| 120 | # Add |
| 121 | result = Matrix(self.row, self.column) |
| 122 | for r in range(self.row): |
| 123 | for c in range(self.column): |
| 124 | result[r, c] = self[r, c] + another[r, c] |
| 125 | return result |
| 126 | |
| 127 | def __neg__(self) -> Matrix: |
| 128 | """ |