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

Method __mul__

linear_algebra_python/src/lib.py:256–275  ·  view source on GitHub ↗

implements the matrix-vector multiplication. implements the matrix-scalar multiplication

(self,other)

Source from the content-addressed store, hash-verified

254 """
255 return self.__height
256 def __mul__(self,other):
257 """
258 implements the matrix-vector multiplication.
259 implements the matrix-scalar multiplication
260 """
261 if isinstance(other, Vector): # vector-matrix
262 if (len(other) == self.__width):
263 ans = zeroVector(self.__height)
264 for i in range(self.__height):
265 summe = 0
266 for j in range(self.__width):
267 summe += other.component(j) * self.__matrix[i][j]
268 ans.changeComponent(i,summe)
269 summe = 0
270 return ans
271 else:
272 raise Exception("vector must have the same size as the " + "number of columns of the matrix!")
273 elif isinstance(other,int) or isinstance(other,float): # matrix-scalar
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.

Callers

nothing calls this directly

Calls 4

zeroVectorFunction · 0.85
MatrixClass · 0.85
componentMethod · 0.45
changeComponentMethod · 0.45

Tested by

no test coverage detected