C5_W4_A1 Exercise 2

In this instruction

apply sin to even indices in the array; 2i

Are we expected to set the np.sin methods “out” and ‘where’? Because I keep getting the error:

ValueError: could not broadcast input array from shape (8,16) into shape (8,8)

but I really feel like it should work just by applying np.sin(angle_rads) and storing it into angle_rads[:, 0::2]

Hi @alexrecouso

The parameter passed to np.sin() is angle_rads[:, ::2]


Oh great, it finally worked. Thank you very much!

I am stuck on this same exercise. Currently I am getting a test error which is stating that the shape of the final positional encoding should be (1, positions, d_model). This shape is apparently meant to be (1, 8, 16). I copied the code I used in the function to a new cell, ran it with positions=8 and d=16, and got the correct shape. Is there something wrong with the grading function?

And likewise, np.cos(angle_rads[:, 1::2]) for those like me who didn’t get it right away :sweat_smile: