Gradient checking issue

Hello, could someone help me troubleshoot this error? Why is vector_to_dictonary undefined?

NameError                                 Traceback (most recent call last)
<ipython-input-13-c57ee5e9e05a> in <module>
      3 cost, cache = forward_propagation_n(X, Y, parameters)
      4 gradients = backward_propagation_n(X, Y, cache)
----> 5 difference = gradient_check_n(parameters, gradients, X, Y, 1e-7, True)
      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"

<ipython-input-12-cf9fbf7b4f17> in gradient_check_n(parameters, gradients, X, Y, epsilon, print_msg)
     42         #print(str(theta_plus))
     43         #theta_plus_dict, _= vector_to_dictonary(theta_plus)
---> 44         J_plus[i], _ =  forward_propagation_n(X,Y,vector_to_dictonary(theta_plus))
     45         #print (str(parameters))
     46         #print(str(parameters_reverse))

NameError: name 'vector_to_dictonary' is not defined

Hi there, do you mind reminding me which assignment/document is this specifically?
Thank you,

Hi @Son_Duong

This vector_to_dictionary is one of the util functions provided by the lab. My first recommendation would be to refresh your lab:

Save your work by clicking the save icon
Click on Help in the upper right corner
Click on Get latest version


Also, are you using the np.linalg.norm to calculate numerator and denominator?

Let me know how it goes.



HI @kchong37 ,

This is for DLS Course 2 Week 1 Assignment 3: Gradient Checking.


1 Like

Thank you, Juan! for pointing out the doc name and providing the response, I will leave this question to you.

1 Like

Thanks Juan,

I tried refreshing everything as you instructed and it’s still not working. vector_to_dictonary seems to work outside of the for loops so its loaded properly. I’m having a little trouble even understanding why I need a for loop in this code-- dont I need to add epsilon to everything element wise? Thanks for your help.

@Son_Duong ,

Just to get it out of the way: by looking at your code, I don’t see the indentation of the sentences under the for loop. Is it because you copied/pasted here and it lost format? This may be a silly question, but lets make sure that this is not the issue.

@Son_Duong also, please delete this code - the code of honor of the platform states that no code should be added to posts. Thank you!

@Son_Duong we found your problem. Credits to @paulinpaloalto

Check out this spelling error:

theta_plus_dict= vector_to_dictonary(theta_plus)


Please fix that and re-run. It should work just fine.


Oh boy, I’ve been staring at that for too long :slight_smile: thanks for your help.