MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / determinant

Method determinant

matrix/matrix_class.py:157–173  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

155 return Matrix(values)
156
157 def determinant(self) -> int:
158 if not self.is_square:
159 return 0
160 if self.order == (0, 0):
161 return 1
162 if self.order == (1, 1):
163 return int(self.rows[0][0])
164 if self.order == (2, 2):
165 return int(
166 (self.rows[0][0] * self.rows[1][1])
167 - (self.rows[0][1] * self.rows[1][0])
168 )
169 else:
170 return sum(
171 self.rows[0][column] * self.cofactors().rows[0][column]
172 for column in range(self.num_columns)
173 )
174
175 def is_invertable(self) -> bool:
176 return bool(self.determinant())

Callers 3

is_invertableMethod · 0.95
inverseMethod · 0.95
get_minorMethod · 0.45

Calls 1

cofactorsMethod · 0.95

Tested by

no test coverage detected