conv.py 954 Bytes
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)))