-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
55 lines (43 loc) · 1.14 KB
/
test.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python
'''
REGEX to replace rowNum+1 with rowNum:
Find what:
\(?([rR]owNum)\ ?\+\ ?1\)?
\(?(*[rR]owNum)\ ?\+\ ?1\)?
Replace with:
\1
'''
def vector_dot (c = 1, A = [], B = []):
#Dot with a vector
if (B != []):
if (len(A) == len(B)):
vect_prod = sum(A[i]*B[i] for i in range (len(A)) #dot the vectors and multiply by scalar
else:
raise ValueError ("Error: can't dot 2 vectors of different lengths.")
return -1
elif (c != 1): #B is empty and c is not. So dot scalar c and vector A
vect_prod = A
vect_prod = [c*vect_prod_i for vect_prod_i in vect_prod] #scalar dot product.
return vect_prod
A = 1
B = 1
def check(k):
if (k == 0):
print ("inside if")
elif (k == 1):
print ("inside elif")
elif (k != 1):
print ("elif k != 1")
if (B != 0):
if (A != B):
print ("Error: can't dot 2 vectors of different lengths")
return None
print ("vect_prod = sum(A[i]*B[i] for i in range (len(A))")
elif (c != 1): #B is empty and c is not. So dot scalar c and vector A
print("vect_prod = A")
print("vect_prod = [c*vect_prod_i for vect_prod_i in vect_prod]" #scalar dot product.
else:
print ("hi!")
check(0)
check(1)
check(2)