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

Method __pow__

matrix/matrix_class.py:340–356  ·  view source on GitHub ↗
(self, other: int)

Source from the content-addressed store, hash-verified

338 )
339
340 def __pow__(self, other: int) -> Matrix:
341 if not isinstance(other, int):
342 raise TypeError("A Matrix can only be raised to the power of an int")
343 if not self.is_square:
344 raise ValueError("Only square matrices can be raised to a power")
345 if other == 0:
346 return self.identity()
347 if other < 0:
348 if self.is_invertable():
349 return self.inverse() ** (-other)
350 raise ValueError(
351 "Only invertable matrices can be raised to a negative power"
352 )
353 result = self
354 for _ in range(other - 1):
355 result *= self
356 return result
357
358 @classmethod
359 def dot_product(cls, row: list[int], column: list[int]) -> int:

Callers

nothing calls this directly

Calls 3

identityMethod · 0.95
is_invertableMethod · 0.95
inverseMethod · 0.95

Tested by

no test coverage detected