# Week 1 Gradient Checking gradient\_check\_n

**URL:** <https://community.deeplearning.ai/t/week-1-gradient-checking-gradient-check-n/23947>\
**Category:** Improving Deep Neural Networks: Hyperparameter tun\
**Tags:** coursera-platform\
**Created:** [July 28, 2021, 6:38pm UTC](https://community.deeplearning.ai/t/week-1-gradient-checking-gradient-check-n/23947 "2021-07-28T18:38:59Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![seth](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/seth/32/3890_2.png) [@seth](https://community.deeplearning.ai/u/seth)\
**Post date:** [July 28, 2021, 6:38pm UTC](https://community.deeplearning.ai/t/week-1-gradient-checking-gradient-check-n/23947/1 "2021-07-28T18:38:59Z")

</div>

For the life of me I can’t figure out what I’m doing wrong here. I see in the output, it’s telling me that I’m not using np.linalg.norm for numerator or denominator … but I am! I need to understand what I’m doing wrong because I am losing some momentum here in this course…please help!

```auto
There is a mistake in the backward propagation! difference = 2.4577112074727173e-07
Error: Wrong output
 0 Tests passed
 1 Tests failed
---------------------------------------------------------------------------
AssertionError Traceback (most recent call last)
<ipython-input-12-0b57cb811a44> in <module>
      6 assert not(type(difference) == np.ndarray), "You are not using np.linalg.norm for numerator or denominator"
      7 
----> 8 gradient_check_n_test(gradient_check_n, parameters, gradients, X, Y)

~/work/release/W1A3/public_tests.py in gradient_check_n_test(target, parameters, gradients, X, Y)
     56 ]
     57 
---> 58 single_test(test_cases, target)
     59 
     60 def predict_test(target):

~/work/release/W1A3/test_utils.py in single_test(test_cases, target)
    122 print('\033[92m', success," Tests passed")
    123 print('\033[91m', len(test_cases) - success, " Tests failed")
--> 124 raise AssertionError("Not all tests were passed for {}. Check your equations and avoid using global variables inside the function.".format(target. __name__ ))
    125 
    126 def multiple_test(test_cases, target):

AssertionError: Not all tests were passed for gradient_check_n. Check your equations and avoid using global variables inside the function.

```

---

<div class="post-metadata">

**Author:** ![seth](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/seth/32/3890_2.png) [@seth](https://community.deeplearning.ai/u/seth)\
**Post date:** [July 29, 2021, 2:43pm UTC](https://community.deeplearning.ai/t/week-1-gradient-checking-gradient-check-n/23947/2 "2021-07-29T14:43:39Z")

</div>

OMG! I hope someone else doesn’t make the silly mistake I made. However, just in case I will humble myself and leave this up for anyone else who does this. Without sharing code, let’s just say that in the for loop we are calculating the grad and gradapprox for every “i-th” example. However, outside the for loop we are using all the training sets. Gulp! Humble pie eating going on here.

---

<div class="post-metadata">

**Author:** ![vitormonteiro](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/vitormonteiro/32/4915_2.png) [@vitormonteiro](https://community.deeplearning.ai/u/vitormonteiro)\
**Post date:** [August 13, 2021, 9:11pm UTC](https://community.deeplearning.ai/t/week-1-gradient-checking-gradient-check-n/23947/3 "2021-08-13T21:11:16Z")

</div>

This helped me out a lot, thanks @seth.

---

<div class="post-metadata">

**Author:** ![Lostfinger](https://avatars.discourse-cdn.com/v4/letter/l/eb9ed0/32.png) [@Lostfinger](https://community.deeplearning.ai/u/Lostfinger)\
**Post date:** [January 13, 2022, 8:47pm UTC](https://community.deeplearning.ai/t/week-1-gradient-checking-gradient-check-n/23947/4 "2022-01-13T20:47:22Z")

</div>

Hi i am encountering the same problem but I didn’t get it, can you be more specific?

---

<div class="post-metadata">

**Author:** ![haheli857](https://avatars.discourse-cdn.com/v4/letter/h/779978/32.png) [@haheli857](https://community.deeplearning.ai/u/haheli857)\
**Post date:** [January 29, 2022, 4:47pm UTC](https://community.deeplearning.ai/t/week-1-gradient-checking-gradient-check-n/23947/5 "2022-01-29T16:47:39Z")

</div>

hope this isnt considered as cheating but basically you need to use the WHOLE thing instead of just the i-th value!

---

<div class="post-metadata">

**Author:** ![Ceren\_A](https://avatars.discourse-cdn.com/v4/letter/c/3ec8ea/32.png) [@Ceren\_A](https://community.deeplearning.ai/u/Ceren_A)\
**Post date:** [October 12, 2022, 6:18pm UTC](https://community.deeplearning.ai/t/week-1-gradient-checking-gradient-check-n/23947/6 "2022-10-12T18:18:54Z")

</div>

If you are getting “Improper number of dimensions to norm” error when computing the difference, try to feed in arrays to np.linalg.norm (put the value in brackets). This worked for me in the previous exercise. In this one, I had to remove the brackets because the values were already arrays.

---

<div class="post-metadata">

**Author:** ![jkh.goh](https://avatars.discourse-cdn.com/v4/letter/j/f04885/32.png) [@jkh.goh](https://community.deeplearning.ai/u/jkh.goh)\
**Post date:** [March 7, 2023, 3:52pm UTC](https://community.deeplearning.ai/t/week-1-gradient-checking-gradient-check-n/23947/7 "2023-03-07T15:52:08Z")

</div>

You are a lifesaver!

---

<div class="post-metadata">

**Author:** ![Asif\_Batada](https://avatars.discourse-cdn.com/v4/letter/a/4bbf92/32.png) [@Asif\_Batada](https://community.deeplearning.ai/u/Asif_Batada)\
**Post date:** [November 12, 2023, 6:56pm UTC](https://community.deeplearning.ai/t/week-1-gradient-checking-gradient-check-n/23947/8 "2023-11-12T18:56:46Z")

</div>

There was no way I could have figured out on my own. Thank you!

---

<div class="post-metadata">

**Author:** ![paulinpaloalto](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/paulinpaloalto/32/187_2.png) [@paulinpaloalto](https://community.deeplearning.ai/u/paulinpaloalto)\
**Post date:** [December 3, 2023, 12:58am UTC](https://community.deeplearning.ai/t/week-1-gradient-checking-gradient-check-n/23947/10 "2023-12-03T00:58:24Z")

</div>


