Hello, I am getting an error when trying to run my propagation on week two’s programming assignment. Here is the code I entered:

```
# YOUR CODE STARTS HERE
A = sigmoid(np.dot(w.T,X) + b)
cost = (-1/m) * np.dot((Y, np.log(A)) + (1 - Y) * np.log(1 - A))
# YOUR CODE ENDS HERE
# BACKWARD PROPAGATION (TO FIND GRAD)
#(≈ 2 lines of code)
# dw = ...
# db = ...
# YOUR CODE STARTS HERE
dw = (1/m) * np.dot(X, (A-Y).T)
db = (1/m) * np.sum(A - Y)
# YOUR CODE ENDS HERE
```

And here is the error I am getting:

```
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-17-698d0096c685> in <module>
3 X =np.array([[1., 2., -1.], [3., 4., -3.2]])
4 Y = np.array([[1, 0, 1]])
----> 5 grads, cost = propagate(w, b, X, Y)
6
7 assert type(grads["dw"]) == np.ndarray
<ipython-input-16-4b7986972471> in propagate(w, b, X, Y)
30 # YOUR CODE STARTS HERE
31 A = sigmoid(np.dot(w.T,X) + b)
---> 32 cost = (-1/m) * np.dot((Y, np.log(A)) + (1 - Y) * np.log(1 - A))
33
34 # YOUR CODE ENDS HERE
<__array_function__ internals> in dot(*args, **kwargs)
TypeError: dot() missing 1 required positional argument: 'b'
```

I appreciate any feedback on this issue, I cannot seem to figure out what is happening here!

Hi @Joe_L21,

You are getting to the right answer, just a little numpy issue.

The error comes from this statement, the call to `np.dot`

is not right.

Here you are passing a tuple to the `np.dot`

, too many parenthesis. Try removing the extra parenthesis from the call to `np.dot`

, remember that function wants two arguments. Also, you need an `np.dot`

call in the second term.

Looking at the notebook, there is a typo in the description of the cost function. Please use this clarification for the video:

I suggest you read the formula for the cost function very carefully and add the parenthesis that are needed, handle the sum over `i`

in both terms using `np.dot`

and make sure to apply the `1/m`

to both terms.

Good luck!

Petri

3 Likes

Thank you for your help @petrifast ! I believe I fixed that issue, but now I am getting a syntax error from these lines:

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

The error is simply:

```
File "<ipython-input-14-f5287c7b3144>", line 42
dw = (1/m) * np.dot(X, (A - Y))
^
SyntaxError: invalid syntax
```

I tried to plug in a very simple equation instead(dw = 1), and I am still getting a syntax error even with that! Do you know what the issue could be?

You probably have a missing parenthesis or some error like that above this equation.

Please try commenting out these two equations and see what happens. Probably an error somewhere else. Then Remove the comment signs from these.

(“Comment out” means add # at the start of the line, it will prevent the line from being executed.)

Then make a copy of your current “cost” equation and paste it again, then comment out one of them. Now you have a copy of the cost function that is commented out (that’s your backup) and another one that is initially the same but not commented out.

You will have to figure out why the cost function row is giving an error. You can simplify it to something trivial like “cost = 0” and see what happens. Maybe add the first term with no.dot. Then add back more pieces from your commented out version. You should find the problem like that.

If it stops making sense go back to your original (commented out) cost function equation and try again.

Good luck!

Petri

2 Likes