mul implements the scalar multiplication and the dot-product
(self, other)
| 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 | """ |