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

Method __mul__

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

mul implements the scalar multiplication and the dot-product

(self, other)

Source from the content-addressed store, hash-verified

134 return Vector(result)
135
136 def __mul__(self, other):
137 """
138 mul implements the scalar multiplication
139 and the dot-product
140 """
141 ans = []
142 if isinstance(other, float) or isinstance(other, int):
143 for c in self.__components:
144 ans.append(c * other)
145 elif isinstance(other, Vector) and (self.size() == other.size()):
146 size = self.size()
147 summe = 0
148 for i in range(size):
149 summe += self.__components[i] * other.component(i)
150 return summe
151 else: # error case
152 raise Exception("invalide operand!")
153 return Vector(ans)
154
155 def copy(self):
156 """

Callers

nothing calls this directly

Calls 4

sizeMethod · 0.95
VectorClass · 0.85
appendMethod · 0.45
componentMethod · 0.45

Tested by

no test coverage detected