-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVector.py
36 lines (29 loc) · 938 Bytes
/
Vector.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
class Vector:
def __init__(self, t):
super().__init__()
self.elements = t
self.dim = len(t)
def scalar_multiplication(self, other):
x = []
for i in self.elements:
x.append(i * other)
return Vector(tuple(x))
# Also known as the dot product
def vector_inner_product(self, other):
raise NotImplementedError
def __rmul__(self, other):
return self.scalar_multiplication(other)
def __mul__(self, other):
return self.scalar_multiplication(other)
def __eq__(self, value):
return (self.elements == value.elements)
def __add__(self, other):
x = []
for i, j in zip(self.elements, other.elements):
x.append(i + j)
return Vector(tuple(x))
def __radd__(self, other):
x = []
for i in self.elements:
x.append(i + other)
return Vector(tuple(x))