MCPcopy Index your code
hub / github.com/geekcomputers/Python / __add__

Method __add__

linear-algebra-python/src/lib.py:356–369  ·  view source on GitHub ↗

implements the matrix-addition.

(self, other)

Source from the content-addressed store, hash-verified

354 return Matrix(matrix, self.__width, self.__height)
355
356 def __add__(self, other):
357 """
358 implements the matrix-addition.
359 """
360 if self.__width == other.width() and self.__height == other.height():
361 matrix = []
362 for i in range(self.__height):
363 row = []
364 for j in range(self.__width):
365 row.append(self.__matrix[i][j] + other.component(i, j))
366 matrix.append(row)
367 return Matrix(matrix, self.__width, self.__height)
368 else:
369 raise Exception("matrix must have the same dimension!")
370
371 def __sub__(self, other):
372 """

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected