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

Method __add__

matrix/matrix_class.py:298–306  ·  view source on GitHub ↗
(self, other: Matrix)

Source from the content-addressed store, hash-verified

296 return self * -1
297
298 def __add__(self, other: Matrix) -> Matrix:
299 if self.order != other.order:
300 raise ValueError("Addition requires matrices of the same order")
301 return Matrix(
302 [
303 [self.rows[i][j] + other.rows[i][j] for j in range(self.num_columns)]
304 for i in range(self.num_rows)
305 ]
306 )
307
308 def __sub__(self, other: Matrix) -> Matrix:
309 if self.order != other.order:

Callers

nothing calls this directly

Calls 1

MatrixClass · 0.70

Tested by

no test coverage detected