C5W3: question about the order of dotor input

I was working on C5W3’s first programming assignment and found a behavior of Dot layer that I don’t understand. E.g.
a.shape = (10, 30, 64)
b.shape = (10, 30, 1)
Dot(axes = 1)(b, a).shape = (10, 1, 64)
Dot(axes = 1)(a, b).shape = (10, 64, 1)

I am confused about why it is computed that way, per my understanding, b will be broadcasted and the result of the operation would be the same. Could anyone help me figure it out? Thanks a lot!

Can you point me to what Exercise in that assignment you are referring to, so I can get a better sense of what you are asking ?

Or is this more of just a general question about taking dot products (i.e. I’m confused what you mean by ‘layer’ here) ?

Hi! The matrix multiplication requires that the number of columns in the first matrix be equal to the number of rows in the second matrix.

Could you provide more context if you are not asking about matrix multiplication?

Thanks for your reply! I was working on C5W3’s programming assignment: Neural_machine_translation_with_attention_v4a. And for the function `one_step_attention` I found out that changing the order of the input to Keras’s Dot layer would change the dimension of the result. Sorry for the confusion!

1 Like

Oh, yes, order is very important-- even in np.dot().