DLS C5W2 Emojify_V1

I have problem with the exercise 2 model and can’t figure out by myself.

I got the following error message:

File “”, line 61
dz = a - Y_oh[i]
^
SyntaxError: invalid syntax

Apparently the dimensions for a and Y_oh[i] in my code are different. I calculated the shape of “a” should be n_y, 1, while Y_oh[i] has 1, n_y. Is my assumption correct?

I tried with z = softmax (a.T), but still got the same error message.

Could you please help me? Thank you very much!

I am not familiar with that assignment, but that kind of syntax error from the python interpreter usually means there is something wrong (incomplete) about the previous line of code. E.g. a missing close paren. :nerd_face:

The “meta” lesson is: if you don’t understand a syntax error, that probably means you are looking in the wrong place. :grinning:

Also note that this is not a dimension mismatch problem. That is not a syntax error and you’ll get a specific message in that case.

Hey @Jade,
Paul Sir is indeed correct. It seems like you are missing a parenthesis from the “just” previous line of code to this line of code, in which you are computing the cost.

Cheers,
Elemento

Thank you for your hint.
I used np.dot for my cost function. Y_oh(i), np.log(a). Is there anything wrong. Y_oh has shape (1, n_y) and a has the shape of (ny,1). From my point of view it should work out, but it doesn’t. I don’t know what is wrong.

Hey @Jade,
If you are unable to figure out the syntax error, can you please DM your code for the function model to me?

Cheers,
Elemento

here my code:

{moderator edit - solution code removed}

Have a more careful look at the cost += line: there are 4 open parens, but only 3 close parens. The editor is syntax aware here: just click on a paren and it will highlight the matching one. Or not :scream_cat:

Also is sentence spelled correctly a few lines earlier?

Hey @Jade,

cost += -np.dot((Y_oh(i), np.log(a))

Also, in the above line of code, Instead of indexing Y_oh with i, you have used it as a function, with i as the argument. It is supposed to be Y_oh[i] instead of Y_oh(i).

Cheers,
Elemento

Thanks, Elemento! I missed those other points! But this is Course 5 here: we are pretty deep into the material here to be worrying about python syntax 101 :nerd_face:

Indeed @paulinpaloalto Sir, Python issues are a more common sight in Course 1, I hardly see any Python issues from Course 2 onwards.

Cheers,
Elemento

Thank you very much for your hints! It works now.