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