Course 1 Week3 update_parameters fails test, but I got the right values and next cells work well

I have a weird issue:

in the function update_parameters I get the following message:

W1 = [[-0.00643025  0.01936718]
 [-0.02410458  0.03978052]
 [-0.01653973 -0.02096177]
 [ 0.01046864 -0.05990141]]
b1 = [[-1.02420756e-06]
 [ 1.27373948e-05]
 [ 8.32996807e-07]
W2 = [[-0.01041081 -0.04463285  0.01758031  0.04747113]]
b2 = [[0.00010457]]
Error: Wrong output for variable W1.
Error: Wrong output for variable b1.
Error: Wrong output for variable W2.
Error: Wrong output for variable b2.
 2  Tests passed
 1  Tests failed

Which is not true as one can verify, these are the same values as the expected output cell ones.

furthermore, the next cells depending on this function pass all the tests

Hi @oscar-defelice,

Congrats, you are making great progress.

The problem you describe does, indeed, look strange. I would suggest two things:

(1) Keep going and submit the notebook once you are done with all of it. There is no penalty for trying. This works if the next steps in your notebook pass their tests. If you start seeing more errors in the laters cells in the notebook, or if the submission comes back with an error, you’ll need to investigate further (step 2).

(2) Investigate further. I would propose adding some test code inside your upgrade_parameters. Please remove this code after you are done with the testing, it’s not correct in general, but will help with this particular issue.

In update_parameters, after you do your computation of W1, b1, W2, b2, copy and paste the following code:

    ## THIS IS A ONLY FOR DEBUGGING update_parameters_test in Exercise 7, please remove
    W1 = np.array([[-0.00643025,  0.01936718],
     [-0.02410458,  0.03978052],
     [-0.01653973, -0.02096177],
     [ 0.01046864, -0.05990141]])
    b1 = np.array([[-1.02420756e-06],
     [ 1.27373948e-05],
     [ 8.32996807e-07],
    W2 = np.array([[-0.01041081, -0.04463285,  0.01758031,  0.04747113]])
    b2 = np.array([[0.00010457]])
    ## END OF DEBUGGING CODE, please remove this code after debugging

Now run the cell for update_parameters and the test cell. Do you still get the error message? This version passes in my notebook. It should pass in yours. If not, there is something strange.

Now comment out my definition of W1. Do you still get an error for W1? And so forth.

Now you can compare the “correct” W1 (for the particular test case) given by the code snippet above and your calculation. Use print statements etc in your version.

Important: Once you find the problem, remove the extra code (like the code I gave above), then rerun the cell and the test cell. Make sure you pass before moving forward.

Let me know if that helps.

Good luck!


1 Like

Hello Petri and thank you!

The only problem was that cell only. Indeed, submitting the assignment made me pass with 90/100 since that only cell produced the error.

I found the issue finally, it was really that I updated the parameters by the synthetic assignment
W1 -= learning_rate*dW1

apparently (I do not explain myself why, thou) this causes the problem. By replacing the assignment with the explicit form
W1 = W1 - learning_rate*dW1

it works fine.


Congrats @oscar-defelice!

Thanks for finding the issue, I’ll pass it along.

I get the same error when I use the W1 -= operation instead of spelling it out. The two ways are both correct, but only one passes here, so there is something subtle about the different ways to calculate the answer. Thanks for pointing this out.


I’m not in the details of the technicalities but the implementation of the -= function in numpy is not exactly equivalent to the explicit assignment.

There are some discussions in Stackoverflow which suggest that the second form creates a new variable and the other form is modifying the array in place and could lead to unexpected results. See example


Another possibility is that the data types of the array variables do not match (int v float), and since shorthand operators will not force type casts, the result could have less precision causing mismatch.


Thank you @albertovilla and @vjmalkoti!

Both of you gave me great observations that will help me.

I am tracking down the difference so we can get it fixed.

Best, Petri

I had the same issue, thanks for posting the answer. Frustrating 2hours … :slight_smile:

Here’s a thread which also goes through the details of why this doesn’t work as expected. It actually does work, but it has some nasty side effects which is why the tests fail if you use this method.