# Gradient Checking Error

**URL:** <https://community.deeplearning.ai/t/gradient-checking-error/80198>\
**Category:** Improving Deep Neural Networks: Hyperparameter tun\
**Tags:** coursera-platform\
**Created:** [December 29, 2021, 10:19am UTC](https://community.deeplearning.ai/t/gradient-checking-error/80198 "2021-12-29T10:19:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mardiyyah\_Oduwole](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/mardiyyah_oduwole/32/10969_2.png) [@Mardiyyah\_Oduwole](https://community.deeplearning.ai/u/Mardiyyah_Oduwole)\
**Post date:** [December 29, 2021, 10:19am UTC](https://community.deeplearning.ai/t/gradient-checking-error/80198/1 "2021-12-29T10:19:24Z")

</div>

![image](https://global.discourse-cdn.com/dlai/original/2X/8/8f8ce51939bf6d58c643f256e548680e29194129.png)  
I am currently having this error and I would appreciate some help.  
I have confirmed the correct usage of np.linalg.norm, I have also confirmed correct arithmetic operations in the numerator and denominator. Kindly help me

Error in text  
**\> There is a mistake in the backward propagation! difference = 1.0**  
**\> ---------------------------------------------------------------------------**  
**\> AssertionError Traceback (most recent call last)**  
**\> in**   
**\> 6 expected\_values = [0.2850931567761623, 1.1890913024229996e-07]**  
**\> 7 assert not(type(difference) == np.ndarray), "You are not using np.linalg.norm for numerator or denominator"**  
**\> ----\> 8 assert np.any(np.isclose(difference, expected\_values)), "Wrong value. It is not one of the expected values"**  
\*\*\> \*\*  
**\> AssertionError: Wrong value. It is not one of the expected values**

---

<div class="post-metadata">

**Author:** ![ai\_curious](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/ai_curious/32/128003_2.png) [@ai\_curious](https://community.deeplearning.ai/u/ai_curious)\
**Post date:** [December 29, 2021, 1:47pm UTC](https://community.deeplearning.ai/t/gradient-checking-error/80198/2 "2021-12-29T13:47:37Z")

</div>

> [@Mardiyyah\_Oduwole](#):
>
> expected\_values = [0.2850931567761623, 1.1890913024229996e-07]

Those are the values expected for `difference` before and after the ‘fix.’ Yours is neither of those, hence the assertion fail. A clue might be that your value is exactly 1.0 which suggests numerator and denominator of a ratio are the same. Maybe trace back to how those values were produced and let us know what you find?

---

<div class="post-metadata">

**Author:** ![Mardiyyah\_Oduwole](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/mardiyyah_oduwole/32/10969_2.png) [@Mardiyyah\_Oduwole](https://community.deeplearning.ai/u/Mardiyyah_Oduwole)\
**Post date:** [December 29, 2021, 7:40pm UTC](https://community.deeplearning.ai/t/gradient-checking-error/80198/3 "2021-12-29T19:40:52Z")

</div>

![image](https://global.discourse-cdn.com/dlai/original/2X/2/2fd94cd7c8670932135059f023b54702e78401de.png)  
This is what I got when I didn’t wrap my parameters\_values by np.copy and used grad[I] for computing the numerator and the denominator. Thank you for your prompt response. I sincerely appreciate

---

<div class="post-metadata">

**Author:** ![ai\_curious](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/ai_curious/32/128003_2.png) [@ai\_curious](https://community.deeplearning.ai/u/ai_curious)\
**Post date:** [December 29, 2021, 9:37pm UTC](https://community.deeplearning.ai/t/gradient-checking-error/80198/4 "2021-12-29T21:37:08Z")

</div>

I’m not sure if your last reply indicates you resolved the problem, or still have it but are getting closer. If the latter, now that you get a floating point number not equal to 1.0, I would recommend go back through the algebra and make sure you are correctly implementing the guidelines. Check for inadvertent cut and paste duplication, using ‘+’ and ‘-’ in the correct places, and operator precedence with nested ().

By the way, using the forum search I found someone else reporting difference = 0.333… and they found a cut and paste error within expressions for `J_plus =` and `J_minus =` where they were both using ‘+’. Hope this helps.

---

<div class="post-metadata">

**Author:** ![Mardiyyah\_Oduwole](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/mardiyyah_oduwole/32/10969_2.png) [@Mardiyyah\_Oduwole](https://community.deeplearning.ai/u/Mardiyyah_Oduwole)\
**Post date:** [December 30, 2021, 6:52am UTC](https://community.deeplearning.ai/t/gradient-checking-error/80198/5 "2021-12-30T06:52:04Z")

</div>

It worked already. The problem was subsetting I for my grad approx values. Thanks so much for helping me out. I am very grateful
