# Excercise 3 (gradient\_check) function inside Gradient\_Checking does not work

**URL:** <https://community.deeplearning.ai/t/excercise-3-gradient-check-function-inside-gradient-checking-does-not-work/4666>\
**Category:** Improving Deep Neural Networks: Hyperparameter tun\
**Tags:** coursera-platform\
**Created:** [May 11, 2021, 5:50am UTC](https://community.deeplearning.ai/t/excercise-3-gradient-check-function-inside-gradient-checking-does-not-work/4666 "2021-05-11T05:50:02Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hsadikot](https://avatars.discourse-cdn.com/v4/letter/h/a9adbd/32.png) [@Hsadikot](https://community.deeplearning.ai/u/Hsadikot)\
**Post date:** [May 11, 2021, 5:50am UTC](https://community.deeplearning.ai/t/excercise-3-gradient-check-function-inside-gradient-checking-does-not-work/4666/1 "2021-05-11T05:50:02Z")

</div>

Hi,

The details of the assignment are under:

Week:Week1  
Assignment: Programming Assignment: Gradient Checking

For the above mentioned exercise notebook I am getting an error in gradient\_checking function. The error is as shown:

 ![error](https://global.discourse-cdn.com/dlai/original/1X/ce514407f0eb7c307b12719452af1c9f7a570f14.png)

Due to this I am not getting the required credit and am failing this assignment

This can be avoided if I reformat the code as following:

```
x, theta = 2, 4
difference = gradient_check(2,4, print_msg=True)

gradient_check_test(gradient_check)

```

But I am unable to delete the original cell nor am I able to format it

I tried to reset the notebook to its original state using checkpoints but am unable to find its original checkpoint

Please help me to solve this issue

Thanks

---

<div class="post-metadata">

**Author:** ![Hsadikot](https://avatars.discourse-cdn.com/v4/letter/h/a9adbd/32.png) [@Hsadikot](https://community.deeplearning.ai/u/Hsadikot)\
**Post date:** [May 11, 2021, 10:05am UTC](https://community.deeplearning.ai/t/excercise-3-gradient-check-function-inside-gradient-checking-does-not-work/4666/2 "2021-05-11T10:05:00Z")

</div>

Hi,

I am still stuck on this only assignment for Week 1. Any assistance could be valuable

---

<div class="post-metadata">

**Author:** ![Devanshu](https://avatars.discourse-cdn.com/v4/letter/d/ee59a6/32.png) [@Devanshu](https://community.deeplearning.ai/u/Devanshu)\
**Post date:** [May 11, 2021, 3:16pm UTC](https://community.deeplearning.ai/t/excercise-3-gradient-check-function-inside-gradient-checking-does-not-work/4666/3 "2021-05-11T15:16:52Z")

</div>

Try running all the cells( even the ones in which you dont have to write code)

---

<div class="post-metadata">

**Author:** ![javier](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/javier/32/47_2.png) [@javier](https://community.deeplearning.ai/u/javier)\
**Post date:** [May 11, 2021, 9:41pm UTC](https://community.deeplearning.ai/t/excercise-3-gradient-check-function-inside-gradient-checking-does-not-work/4666/4 "2021-05-11T21:41:22Z")

</div>

Hi @Hsadikot , welcome to the DLS !

There is a subtle error in your code. Please look carefully at your code and the code provided for that exercise.

---

<div class="post-metadata">

**Author:** ![Hsadikot](https://avatars.discourse-cdn.com/v4/letter/h/a9adbd/32.png) [@Hsadikot](https://community.deeplearning.ai/u/Hsadikot)\
**Post date:** [May 12, 2021, 4:45am UTC](https://community.deeplearning.ai/t/excercise-3-gradient-check-function-inside-gradient-checking-does-not-work/4666/5 "2021-05-12T04:45:06Z")

</div>

Hi @javier

I understand that there may be error in my code. But I am not allowed to edit that particular cell.

Any way in which I can reset the notebook to its original condition

---

<div class="post-metadata">

**Author:** ![Hsadikot](https://avatars.discourse-cdn.com/v4/letter/h/a9adbd/32.png) [@Hsadikot](https://community.deeplearning.ai/u/Hsadikot)\
**Post date:** [May 12, 2021, 5:52am UTC](https://community.deeplearning.ai/t/excercise-3-gradient-check-function-inside-gradient-checking-does-not-work/4666/6 "2021-05-12T05:52:00Z")

</div>

Hi @Devanshu

I execute each cells but I get the error

---

<div class="post-metadata">

**Author:** ![javier](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/javier/32/47_2.png) [@javier](https://community.deeplearning.ai/u/javier)\
**Post date:** [May 12, 2021, 11:23pm UTC](https://community.deeplearning.ai/t/excercise-3-gradient-check-function-inside-gradient-checking-does-not-work/4666/7 "2021-05-12T23:23:51Z")

</div>

Hi @Hsadikot , please send me by direct message the code of your gradient\_check function so i can take a look at it.

---

<div class="post-metadata">

**Author:** ![nramon](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/nramon/32/129097_2.png) [@nramon](https://community.deeplearning.ai/u/nramon)\
**Post date:** [May 14, 2021, 8:50am UTC](https://community.deeplearning.ai/t/excercise-3-gradient-check-function-inside-gradient-checking-does-not-work/4666/8 "2021-05-14T08:50:55Z")

</div>

Hi, @javier.

I had already taken a look at the code. Sorry for not replying sooner.

For other learners experiencing the same error, never write code outside these blocks:

```auto
# YOUR CODE STARTS HERE

# YOUR CODE ENDS HERE

```

---

<div class="post-metadata">

**Author:** ![javier](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/javier/32/47_2.png) [@javier](https://community.deeplearning.ai/u/javier)\
**Post date:** [May 14, 2021, 12:27pm UTC](https://community.deeplearning.ai/t/excercise-3-gradient-check-function-inside-gradient-checking-does-not-work/4666/9 "2021-05-14T12:27:18Z")

</div>

Hey @nramon , at first I also thought that this was the case, but I looked at his implementation and it seemed that the notebook was an old version.

I guided him to update the notebook to the latest release, and now it worked.

---

<div class="post-metadata">

**Author:** ![nramon](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/nramon/32/129097_2.png) [@nramon](https://community.deeplearning.ai/u/nramon)\
**Post date:** [May 14, 2021, 12:33pm UTC](https://community.deeplearning.ai/t/excercise-3-gradient-check-function-inside-gradient-checking-does-not-work/4666/10 "2021-05-14T12:33:42Z")

</div>

He did confirm it worked. Thanks, @javier 🙂

---

<div class="post-metadata">

**Author:** ![aleksandra16](https://avatars.discourse-cdn.com/v4/letter/a/9f8e36/32.png) [@aleksandra16](https://community.deeplearning.ai/u/aleksandra16)\
**Post date:** [July 29, 2022, 9:55am UTC](https://community.deeplearning.ai/t/excercise-3-gradient-check-function-inside-gradient-checking-does-not-work/4666/11 "2022-07-29T09:55:56Z")

</div>

To all having problem with difference equal to app. 0.9999: do not forget to add appropriate brackets in “gradapprox = …” line (in order to ensure the correct order of caluculations).
