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

Method __mul__

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

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

(self, other)

Source from the content-addressed store, hash-verified

325 return self.__height
326
327 def __mul__(self, other):
328 """
329 implements the matrix-vector multiplication.
330 implements the matrix-scalar multiplication
331 """
332 if isinstance(other, Vector): # vector-matrix
333 if other.size() == self.__width:
334 ans = zeroVector(self.__height)
335 for i in range(self.__height):
336 summe = 0
337 for j in range(self.__width):
338 summe += other.component(j) * self.__matrix[i][j]
339 ans.changeComponent(i, summe)
340 summe = 0
341 return ans
342 else:
343 raise Exception(
344 "vector must have the same size as the "
345 + "number of columns of the matrix!"
346 )
347 elif isinstance(other, int) or isinstance(other, float): # matrix-scalar
348 matrix = []
349 for i in range(self.__height):
350 row = []
351 for j in range(self.__width):
352 row.append(self.__matrix[i][j] * other)
353 matrix.append(row)
354 return Matrix(matrix, self.__width, self.__height)
355
356 def __add__(self, other):
357 """

Callers

nothing calls this directly

Calls 6

zeroVectorFunction · 0.85
MatrixClass · 0.85
sizeMethod · 0.80
componentMethod · 0.45
changeComponentMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected