# Assertion error in Week 3 programming assignment

**URL:** <https://community.deeplearning.ai/t/assertion-error-in-week-3-programming-assignment/530118>\
**Category:** Linear Algebra for Machine Learning and Data Sc...\
**Created:** [December 29, 2023, 11:00am UTC](https://community.deeplearning.ai/t/assertion-error-in-week-3-programming-assignment/530118 "2023-12-29T11:00:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Taimoor\_Abrejo](https://avatars.discourse-cdn.com/v4/letter/t/fbc32d/32.png) [@Taimoor\_Abrejo](https://community.deeplearning.ai/u/Taimoor_Abrejo)\
**Post date:** [December 29, 2023, 11:00am UTC](https://community.deeplearning.ai/t/assertion-error-in-week-3-programming-assignment/530118/1 "2023-12-29T11:00:33Z")

</div>

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:

---

<div class="post-metadata">

**Author:** ![Kic](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/kic/32/76339_2.png) [@Kic](https://community.deeplearning.ai/u/Kic)\
**Post date:** [December 29, 2023, 11:15am UTC](https://community.deeplearning.ai/t/assertion-error-in-week-3-programming-assignment/530118/2 "2023-12-29T11:15:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Taimoor\_Abrejo](https://avatars.discourse-cdn.com/v4/letter/t/fbc32d/32.png) [@Taimoor\_Abrejo](https://community.deeplearning.ai/u/Taimoor_Abrejo)\
**Post date:** [December 29, 2023, 2:15pm UTC](https://community.deeplearning.ai/t/assertion-error-in-week-3-programming-assignment/530118/3 "2023-12-29T14:15:59Z")

</div>

Understood. I’ve updated the topic.

---

<div class="post-metadata">

**Author:** ![Kic](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/kic/32/76339_2.png) [@Kic](https://community.deeplearning.ai/u/Kic)\
**Post date:** [December 29, 2023, 4:02pm UTC](https://community.deeplearning.ai/t/assertion-error-in-week-3-programming-assignment/530118/4 "2023-12-29T16:02:43Z")

</div>

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())

---

<div class="post-metadata">

**Author:** ![Taimoor\_Abrejo](https://avatars.discourse-cdn.com/v4/letter/t/fbc32d/32.png) [@Taimoor\_Abrejo](https://community.deeplearning.ai/u/Taimoor_Abrejo)\
**Post date:** [December 29, 2023, 7:32pm UTC](https://community.deeplearning.ai/t/assertion-error-in-week-3-programming-assignment/530118/5 "2023-12-29T19:32:40Z")

</div>

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]))

---

<div class="post-metadata">

**Author:** ![Kic](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/kic/32/76339_2.png) [@Kic](https://community.deeplearning.ai/u/Kic)\
**Post date:** [December 30, 2023, 2:45pm UTC](https://community.deeplearning.ai/t/assertion-error-in-week-3-programming-assignment/530118/6 "2023-12-30T14:45:23Z")

</div>

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.
