# Codebook, wrong output in shape of an array

Hi, I have the following error in Codebook Codercise F.1.4:
Error: operands could not be broadcast together with shapes (8,) (4,)

I have run it in my jupyter notebook and I have shape (8,)
Best,

I am running this code

def fft_multiplication(poly_a, poly_b):
“”"Returns the result of multiplying two polynomials

Args:
poly_a (array[complex]): 1-D array of coefficients
poly_b (array[complex]): 1-D array of coefficients

Returns:
array[complex]: complex coefficients of the product
of the polynomials
"""
##################
##################

# Calculate the number of values required
value= len(poly_a)+ len(poly_b)+ 1
# Figure out the nearest power of 2
n= nearest_power_of_2(value)
# Pad zeros to the polynomial
# Convert the polynomials to value representation
value_a= coefficients_to_values(poly_a)
value_b= coefficients_to_values(poly_b)
# Multiply
#value_c= np.zeros((n,),dtype=complex)
#for index in range(n):
#    value_c[index]= value_a[index] * value_b[index]
value_c= np.multiply(value_a,value_b)
#print(value_c)
# Convert back to coefficient representation
return values_to_coefficients(value_c)


This post helped me

1 Like

Glad to know you figured it out! Yes, it’s a bit sneaky

1 Like
##################
##################

# Calculate the number of values required
n=max(len(poly_a), len(poly_b))+1
# Figure out the nearest power of 2
np2=nearest_power_of_2(n)

# Pad zeros to the polynomial