Program to generate an array having convolution of two given arrays | Python3 program for the above approach ; Function to generate a convolution array of two given arrays ; Stores the size of arrays ; Stores the final array ; Traverse the two given arrays ; Update the convolution array ; Print the convolution array c [ ] ; Driver Code
MOD = 998244353 NEW_LINE def findConvolution ( a , b ) : NEW_LINE INDENT global MOD NEW_LINE n , m = len ( a ) , len ( b ) NEW_LINE c = [ 0 ] * ( n + m - 1 ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT for j in range ( m ) : NEW_LINE INDENT c [ i + j ] += ( a [ i ] * b [ j ] ) % MOD NEW_LINE DEDENT DEDENT for k in range ( len ( c ) ) : NEW_LINE INDENT c [ k ] %= MOD NEW_LINE print ( c [ k ] , end = " ▁ " ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT A = [ 1 , 2 , 3 , 4 ] NEW_LINE B = [ 5 , 6 , 7 , 8 , 9 ] NEW_LINE findConvolution ( A , B ) NEW_LINE DEDENT