Week 2 ex 5. Error dw


I keep getting an error in the dw formula and I cannot find out what I am doing wrong. Anyone that can help?

File “”, line 40
dw = 1/m * np.dot(X,((A-Y).T))
SyntaxError: invalid syntax

Thanks in advance

Take a close look at the syntax of the operator np.dot()

I am sorry, but I don’t know what you mean. I am trying different combinations for 2 days by now and apparently I just don’t get it.
Is there somewhere a site that can tell me how this works?

Thanks in advance

The problem is not on that line: it is on the previous line. You probably have a missing close paren or close bracket. Note that the notebook editor is syntax aware: you can use it to check for matching delimiters.

The clue is that when the syntax error literally points at the first character in the line, it usually means the error is on the previous line. Well, you can get an error like that for bad indentation, but the python interpreter will usually explicitly say if the problem is indentation.

Thank you!
The error was in the previous line indeed.

Kind regards

1 Like

It might seem strange that the error gets reported that way, but you have to think about it from the interpreter’s point of view. It gets to the end of the previous line and it’s still waiting for a close paren, so it says “Hmmm, I guess I need to keep looking and maybe I’ll find what I’m waiting for on the next line”. But then it gets to the next line and says “Hey, wait a minute, the name of a new variable does not fit with the syntax if what I’m looking for is a close paren”. So the error gets reported on the next line. And if you think about it, that’s actually correct: the error is that the first character on the next line is not a close paren, so the syntax error really is on that line even though it was caused by something on the previous line.