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

Method __sub__

linear_algebra/src/lib.py:303–317  ·  view source on GitHub ↗

implements matrix subtraction.

(self, other: Matrix)

Source from the content-addressed store, hash-verified

301 raise Exception("matrix must have the same dimension!")
302
303 def __sub__(self, other: Matrix) -> Matrix:
304 """
305 implements matrix subtraction.
306 """
307 if self.__width == other.width() and self.__height == other.height():
308 matrix = []
309 for i in range(self.__height):
310 row = [
311 self.__matrix[i][j] - other.component(i, j)
312 for j in range(self.__width)
313 ]
314 matrix.append(row)
315 return Matrix(matrix, self.__width, self.__height)
316 else:
317 raise Exception("matrices must have the same dimension!")
318
319 @overload
320 def __mul__(self, other: float) -> Matrix: ...

Callers

nothing calls this directly

Calls 5

widthMethod · 0.80
heightMethod · 0.80
MatrixClass · 0.70
componentMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected