Polynomial multiplication by convolution python

lst1 = [2,3,4]
lst2 = [1,2,3]
def func_mu(lst1,lst2):
    lst = []
    count = len(lst1)+len(lst2)-1 #循环进行次数
    count_hou = count//2 #后半部分次数
    for i in range(count):
        juanji = 0
        if (i<=count_hou):
            for j in range(i+1):
                juanji += lst1[j]*lst2[i-j]
            lst.append(juanji)
        else:
            for j in range(i- count_hou, count_hou+1):
                juanji += lst1[j]*lst2[i-j]
            lst.append(juanji)
    return lst
print(func_mu(lst1,lst2))

Guess you like

Origin blog.csdn.net/qq_60943902/article/details/126767748