C5_W2_A2 Exercise 1

I keep getting the error:

operands could not be broadcast together with shapes (50,) (2,) (50,)

Any idea what might be causing it?

Your code is trying to combine two variables that don’t have compatible shapes.

But im initializing avg with np.zeros with shape (50,) isnt that right?

No. Is every set of data going to always have shape (50,0)?

There are hints for this in the instructions:

The code provides the variable “any_word” specifically for this purpose.

Because it says:

Returns:
avg – average vector encoding information about the sentence, numpy-array of shape (50,)

But since any_word is a str i can’t apply the shape method. What shall I try instead? Thank you!

I will submit an issue to the course authors to remove the (50,) from the function header. Hard-coded values should not be used, since the function should be a general-purpose tool.

Use “any_word” as a key to the “word_to_vec_map” dictionary, and then add the “shape” attribute.

1 Like

Thank you so much, it finally worked!