MCPcopy Index your code
hub / github.com/subbarayudu-j/TheAlgorithms-Python / __add__

Method __add__

linear_algebra_python/src/lib.py:276–289  ·  view source on GitHub ↗

implements the matrix-addition.

(self,other)

Source from the content-addressed store, hash-verified

274 matrix = [[self.__matrix[i][j] * other for j in range(self.__width)] for i in range(self.__height)]
275 return Matrix(matrix,self.__width,self.__height)
276 def __add__(self,other):
277 """
278 implements the matrix-addition.
279 """
280 if (self.__width == other.width() and self.__height == other.height()):
281 matrix = []
282 for i in range(self.__height):
283 row = []
284 for j in range(self.__width):
285 row.append(self.__matrix[i][j] + other.component(i,j))
286 matrix.append(row)
287 return Matrix(matrix,self.__width,self.__height)
288 else:
289 raise Exception("matrix must have the same dimension!")
290 def __sub__(self,other):
291 """
292 implements the matrix-subtraction.

Callers

nothing calls this directly

Calls 4

MatrixClass · 0.85
widthMethod · 0.80
heightMethod · 0.80
componentMethod · 0.45

Tested by

no test coverage detected