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

Method __mul__

linear_algebra_python/src/lib.py:115–130  ·  view source on GitHub ↗

mul implements the scalar multiplication and the dot-product

(self,other)

Source from the content-addressed store, hash-verified

113 else: # error case
114 raise Exception("must have the same size")
115 def __mul__(self,other):
116 """
117 mul implements the scalar multiplication
118 and the dot-product
119 """
120 if isinstance(other,float) or isinstance(other,int):
121 ans = [c*other for c in self.__components]
122 return ans
123 elif (isinstance(other,Vector) and (len(self) == len(other))):
124 size = len(self)
125 summe = 0
126 for i in range(size):
127 summe += self.__components[i] * other.component(i)
128 return summe
129 else: # error case
130 raise Exception("invalide operand!")
131 def copy(self):
132 """
133 copies this vector and returns it.

Callers

nothing calls this directly

Calls 1

componentMethod · 0.45

Tested by

no test coverage detected