Return -self. Example: >>> a = Matrix(2, 2, 3) >>> a[0, 1] = a[1, 0] = -2 >>> -a Matrix consist of 2 rows and 2 columns [-3, 2] [ 2, -3]
(self)
| 125 | return result |
| 126 | |
| 127 | def __neg__(self) -> Matrix: |
| 128 | """ |
| 129 | <method Matrix.__neg__> |
| 130 | Return -self. |
| 131 | Example: |
| 132 | >>> a = Matrix(2, 2, 3) |
| 133 | >>> a[0, 1] = a[1, 0] = -2 |
| 134 | >>> -a |
| 135 | Matrix consist of 2 rows and 2 columns |
| 136 | [-3, 2] |
| 137 | [ 2, -3] |
| 138 | """ |
| 139 | |
| 140 | result = Matrix(self.row, self.column) |
| 141 | for r in range(self.row): |
| 142 | for c in range(self.column): |
| 143 | result[r, c] = -self[r, c] |
| 144 | return result |
| 145 | |
| 146 | def __sub__(self, another: Matrix) -> Matrix: |
| 147 | return self + (-another) |