Why does the error message ask me to use * instead of @? #3
-
For the function projection_matrix_1d, this is how my function looks like: def projection_matrix_1d(b): D, = b.shape
But I got the following error message:For the function projection_matrix_1d, this is how my function looks like: def projection_matrix_1d(b): D, = b.shape
But I got the following error message: I am confused here, (b@b.T/b@b) is the projection matrix, so we are supposed to use @ when we multiply np.eye(D) with the projection matrix but the error message asked me to use '*' instead. Why is that? From what I know, '*' will produce element-wise multiplication, which is obviously incorrect My second question is do we really need to use the np.eye(D), can we NOT use it? Will it make any difference for the autograder had we not used the np.eye(D)? Similar to other functions, can we NOT use the np.eye and np.zeros? Can you please give some light? Really appreciate it. Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
I believe something is fishy with using b@b.T. 1D arrays in Numpy do not always behave like vectors. Try and check what the result for b@b.T is. One piece of advice I would give when you debug errors like this is to break the long expression into smaller parts. For example, you have "P = np.eye(D) @ ((b @ b.T) / (b @ b))". This error you have occurred because one of the operand of your @ operator is a scalar. But which one is it?
Also, I would suggest checking out numpy.outer. |
Beta Was this translation helpful? Give feedback.
-
Hi TheKidPadra, Thanks for the advice. I have debugged as you suggested. I know where my mistake is. Numpy.outer works! Thanks. |
Beta Was this translation helpful? Give feedback.
I believe something is fishy with using b@b.T. 1D arrays in Numpy do not always behave like vectors.
Try and check what the result for b@b.T is. One piece of advice I would give when you debug errors like this is to break the long expression into smaller parts. For example, you have "P = np.eye(D) @ ((b @ b.T) / (b @ b))". This error you have occurred because one of the operand of your @ operator is a scalar. But which one is it?