Course 1 week 3 assignment, W2 shape

in line 16 I get an error related to the dimension of array W2, but as you can see in immage attached the shape of W2 is correct. The remain parts of the assigmnent run fine. can I submit or I need to modify something?

Hey @Manuel_Angelini,
Welcome to the community. Indeed, this behaviour is really weird. Can you please try to re-run all the cells once, and let us know if this behaviour is reproduced? Also, do try to submit the notebook once and let us know the output of the auto-grader including the score and the error messages (if any).

Cheers,
Elemento

I have already tried to rerun all the cells and also to clear all the output and restart the kernel but the issue remain. So, I’ll submit and I’ll let you know.

thanks a lot,

Best regards

I submitted and I recived an 88% score because the line 16 was considered as an error. what I have to do?

Hey @Manuel_Angelini,
The grader must have produced an error. Can you please share that as well?

Cheers,
Elemento

[ValidateApp | INFO] Validating ‘/home/jovyan/work/submitted/courseraLearner/W3A1/Planar_data_classification_with_one_hidden_layer.ipynb’
[ValidateApp | INFO] Executing notebook with kernel: python3
[ValidateApp | ERROR] Timeout waiting for execute reply (30s).
[ValidateApp | ERROR] Interrupting kernel
Tests failed on 1 cell(s)! These tests could be hidden. Please check your submission.

The following cell failed:

np.random.seed(2)
n_x, n_h, n_y = initialize_parameters_test_case()
parameters = initialize_parameters(n_x, n_h, n_y)

print("W1 = " + str(parameters["W1"]))
print("b1 = " + str(parameters["b1"]))
print("W2 = " + str(parameters["W2"]))
print("b2 = " + str(parameters["b2"]))

initialize_parameters_test(initialize_parameters)

The error was:

---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-10-0eb4c3a6d62e> in <module>
      8 print("b2 = " + str(parameters["b2"]))
      9 
---> 10 initialize_parameters_test(initialize_parameters)

~/work/submitted/courseraLearner/W3A1/public_tests.py in initialize_parameters_test...
     54     assert parameters["W1"].shape == expected_output["W1"].shape, f"Wrong s...
     55     assert parameters["b1"].shape == expected_output["b1"].shape, f"Wrong s...
---> 56     assert parameters["W2"].shape == expected_output["W2"].shape, f"Wrong s...
     57     assert parameters["b2"].shape == expected_output["b2"].shape, f"Wrong s...
     58 

AssertionError: Wrong shape for W2.

Notice that there are actually two completely separate tests there: one you can see in the notebook and one that is from public_tests.py. What that indicates is you get the correct shape on the first test, but not on the second one. One type of error that can cause that is “hard-coding” dimensions in a way that happens to match one test case, but is not “general”. The two test cases try to catch that type of error by using different dimensions probably. Another version of “hard-coding” is to reference global variables within the body of your function, instead of the actual parameters that were passed in.

I just looked at the tests again and I’ll bet what you did was to “hard-code” the n_h value to 4 in your code instead of using the parameter value of n_h that was passed in.

BTW you had originally titled this as being from Week 4, but it’s actually the Week 3 assignment you are talking about. I edited the title of the thread for you to correct that by using the little “edit pencil” on the title.