conv.py
954 Bytes
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
import math
arr = [7,2,4,3,2,9,6,8,9,1]
arr2= [3,6,2,8,6,9,1,5,7,3,0,8,5]
arr3 = [7,2,4,3,2]
kernel = [7,2,4,3,2]
def conv(arrs):
s = len(kernel)
result = []
midpos = math.floor(s/2)
for i in range(0,midpos):
arrs.insert(0,0)
arrs.append(0)
for j in range(midpos,len(arrs) - midpos):
convResult = 0
for i in range(0, s):
convResult = convResult + (kernel[i] * arrs[j - midpos + i])
result.append(convResult)
return max(result)
def normalize(arrs):
maximum = max(arrs)
minimum = min(arrs)
denom = maximum - minimum
for i in range(0,len(arrs)):
arrs[i] = (arrs[i] - minimum)/ denom
normalize(arr)
normalize(arr2)
inputs = []
recommend = []
inputs.append(arr)
inputs.append(arr2)
inputs.append(arr3)
for i in inputs:
recommend.append(conv(i))
print(max(recommend), recommend.index(max(recommend)))