Hello. I have invalid syntax

dw = (1/m)*np.dot(((A-Y).T),X)

^

SyntaxError: invalid syntax

Help me please

I need to get the vector as in the training laboratory

### VECTORIZED GENERAL DOT PRODUCT

tic = time.process_time()

dot = np.dot(W,x1)

toc = time.process_time()

print ("gdot = " + str(dot) + "\n ----- Computation time = " + str(1000 * (toc - tic)) + â€śmsâ€ť)

gdot = [25.89872885 27.60612795 18.06528476]

As a result, a vector with dimension W

I donâ€™t see the invalid syntax here. I do think that the dot product has an issue due to the params passed, but not a syntax one. Could you share your code via DM so that I look at previous lines as well?

Thanks,

Juan

If you canâ€™t find a syntax error, it usually means you are looking in the wrong place â€¦

That kind of error thrown at the beginning of a line usually means you have a missing close paren or close bracket on the *previous* non-comment line.

Thanks @paulinpaloalto , I thought I was in need of a new set of glasses â€¦ but just in case, I did ask @plohih_love for the code to follow your advice

Now, regarding the current line of code:

dw = (1/m)*np.dot(((A-Y).T),X)

â€¦ donâ€™t you think there may be an issue in the dot parameters?

Juan

Yes, just from a â€śdimensional analysisâ€ť perspective, that is wrong. (A - Y)^T will have dimension m x 1 whereas X is n_x x m.

@plohih_love have a look again at the instructions where they give the mathematical formula for dw and itâ€™s a bit different than what that code does. From a notational perspective, note that what Prof Ng means by dw is:

dw = \displaystyle \frac {\partial J}{\partial w}

Thank you. You were right: the previous line without comments is missing a closing parenthesis or closing parenthesis.

thanks again. I was frustrated by this mistake, so I began to doubt my knowledge of vector algebra and therefore changed the order, although the original code was: dw = (1/m)*np.dot(X,((A-Y).T)).

A lot of people find this behavior surprising, but you have to think about it from the point of view of the python interpreter: it gets to the end of a line and knows that the syntax is incomplete and that it still needs a closing delimiter. But the syntax allows statements to continue onto the next line, right? So it continues forward onto the next line and then it â€śthrowsâ€ť there when it sees something that conflicts with the closing parenthesis that it is looking for.

Now that youâ€™ve found the syntax error, if you have not reviewed the dot product, youâ€™ll get to a new error. If you did review the order of the params in that dot product, then you should have good results.

Good day. Yes i got good results on dw,db , but bad on cost:

dw = [[ 0.25071532]

[-0.06604096]]

db = -0.1250040450043965

cost = -2.1428184225087668

I did the calculation: cost = -(1/m)*(np.dot(Y,(np.log(A)).T)+np.dot((1-Y),(1-np.log(A)).T))

I found a mistake))) Correctly write np.log(1-A), wrong 1-np.log(A)

Thanks everyone