Week 2 exercise 4.3

pl correct me. I am getting the following error.

NameError Traceback (most recent call last)
in
3 X =np.array([[1., 2., -1.], [3., 4., -3.2]])
4 Y = np.array([[1, 0, 1]])
----> 5 grads, cost = propagate(w, b, X, Y)
6
7 assert type(grads[“dw”]) == np.ndarray

in propagate(w, b, X, Y)
29 # cost = …
30 # YOUR CODE STARTS HERE
—> 31 A=sigmoid(np.dot(w.T,X)+b)
32 cost = -1/m * (np.dot(Y,np.log(A).T) + np.dot((1-Y),np.log(1 - A).T))
33 # YOUR CODE ENDS HERE

NameError: name ‘sigmoid’ is not defined

Hi @srilika and welcome to the DL Specialization! The NameError indicates that the sigmoid(...) function that you wrote earlier in the notebook, is not available in the “namespace”. That is, Python cannot find it. So first be sure that you completed that function, and importantly, run it and check that it passes. By running that cell, Python will recognize the existence of the function.

1 Like

I got it. thank you very much

Great! The important thing to realize is that @kenb’s point there is a completely general one: every time you close and reopen the notebook or restart the “Kernel”, you need to rerun all the previous cells in the notebook to populate the “namespace” that Ken described. It looks misleading when you open the notebook, because you see all the printed output from the last time you run things. But the point is that the “runtime state” in memory (the “namespace”) is not populated and needs to be recreated every time. There is a topic about this on the FAQ Thread, which is worth a look just on general principles. :nerd_face:

3 Likes