1 # A simple vector class
10 def __init__(self
, *v
):
13 def fromlist(self
, v
):
14 if not isinstance(v
, list):
20 return 'vec(' + repr(self
.v
)[1:-1] + ')'
25 def __getitem__(self
, i
):
28 def __add__(self
, other
):
29 # Element-wise addition
30 v
= map(lambda x
, y
: x
+y
, self
, other
)
31 return Vec().fromlist(v
)
33 def __sub__(self
, other
):
34 # Element-wise subtraction
35 v
= map(lambda x
, y
: x
-y
, self
, other
)
36 return Vec().fromlist(v
)
38 def __mul__(self
, scalar
):
40 v
= map(lambda x
: x
*scalar
, self
.v
)
41 return Vec().fromlist(v
)