MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / __neg__

Method __neg__

matrix/sherman_morrison.py:127–144  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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)

Callers

nothing calls this directly

Calls 1

MatrixClass · 0.70

Tested by

no test coverage detected