Assertion error in Week 3 programming assignment

There is an assertion error in the Week 3 programming assignment, precisely in Exercise 4.
Here’s the error:
AssertionError Traceback (most recent call last)
in
----> 1 w3_unittest.test_forward_propagation(forward_propagation)

~/work/w3_unittest.py in test_forward_propagation(target_forward_propagation)
289
290 for test_case in test_cases:
→ 291 result = target_forward_propagation(
292 test_case[“input”][“X”],
293 test_case[“input”][“parameters”],

in forward_propagation(X, parameters, n_y)
22 ### END CODE HERE ###
23
—> 24 assert(Y_hat.shape == (n_y, X.shape[1]))
25
26 return Y_hat

AssertionError:

1 Like

Hi @Taimoor_Abrejo ,

Please include the error message when posting your query, not a link to your assignment. The community members in general can not access your workspace.

Understood. I’ve updated the topic.

1 Like

Hi @Taimoor_Abrejo ,

The AssertionError is raised because the shape of Y_hat is not as expected. You can check you code by printing the shape of X and the value of n_y to trace where in the code has gone wrong.

Here is an example of a print statement to print the shape of X:
print('shape of X: ', X.shape())

That’s odd, since, when checking by using an if statement, this condition is returning True, while the “assert()” function is still raising the error.

Here’s the if statement that returns True on execution:
if Y_hat.shape == (n_y, X.shape[1]):
print(“True”)

And, here’s the assert function:
assert(Y_hat.shape == (n_y, X.shape[1]))

Hi @Taimoor_Abrejo ,

The best way to be sure is to print the shape of y_hat.
The print statement shown here is in the same block level as the if statement, so ‘True’ is the output. In order to do want you wanted, you need to indent one block level to the right, so that the print statement is within the logic of the if statement.
Also, don’t forget to clear all the output and rerun the code cell from the beginning of the notebook.