File tree Expand file tree Collapse file tree 1 file changed +11
-11
lines changed
3_advanced/chapter13/examples Expand file tree Collapse file tree 1 file changed +11
-11
lines changed Original file line number Diff line number Diff line change @@ -11,40 +11,40 @@ def __init__(self, vals):
11
11
# print("Assigned values ", vals, " to vector.")
12
12
13
13
"""
14
- String Function
14
+ String Function
15
15
16
- Converts the object to a string in readable format for programmers
17
- """
16
+ Converts the object to a string in readable format for programmers
17
+ """
18
18
19
19
def __str__ (self ):
20
20
return str (self .vals )
21
21
22
22
"""
23
- Elementwise power: raises each element in our vector to the given power
24
- """
23
+ Elementwise power: raises each element in our vector to the given power
24
+ """
25
25
26
26
def __pow__ (self , power ):
27
27
return Vector ([i ** power for i in self .vals ])
28
28
29
29
"""
30
- Addition: adds each element to corresponding element in other vector
31
- """
30
+ Addition: adds each element to corresponding element in other vector
31
+ """
32
32
33
33
def __add__ (self , vec ):
34
34
return Vector (
35
35
[self .vals [i ] + vec .vals [i ] for i in range (len (self .vals ))]
36
36
)
37
37
38
38
"""
39
- Multiplies each element in the vector by a specified constant
40
- """
39
+ Multiplies each element in the vector by a specified constant
40
+ """
41
41
42
42
def __mul__ (self , constant ):
43
43
return Vector ([self .vals [i ] * constant for i in range (len (self .vals ))])
44
44
45
45
"""
46
- Elementwise subtraction: does the same as addition, just subtraction instead
47
- """
46
+ Elementwise subtraction: does the same as addition, just subtraction instead
47
+ """
48
48
49
49
def __sub__ (self , vec ):
50
50
return self + (vec * (- 1 ))
You can’t perform that action at this time.
0 commit comments