Question about error in W2 assignment

When I create sigmoid function with one line of code, I keep getting this error, and I don’t understand why. Please help!

NameError Traceback (most recent call last)
----> 1 print ("sigmoid([0, 2]) = " + str(sigmoid(np.array([0,2]))))
3 sigmoid_test(sigmoid)

NameError: name ‘np’ is not defined

You filed this under DLS Course 5 Sequence Models, but I’m guessing that you are asking about the Intro to Numpy assignment in DLS C1 W2.

The answer on “np not defined” is that it means you have not run the earlier cells in the notebook where the “import” command for numpy happened. Just do “Cell → Run All Above” and then run your test cell again and that should fix this.

Note that you need to run all the cells every time you reopen or restart the notebook. There is usually a cell very early in the notebook that imports all the packages that will be needed. I think this was discussed on the video “A Quick Introduction to the Jupyter Notebooks” in Week 2, but it’s been a while since I watched that lecture.

There is also a topic about this on the DLS FAQ Thread, which is worth a look in general if you are just starting DLS C1.

1 Like

Thank you so much! it worked

1 Like

That’s great news! Thanks for confirming.

PS - I went ahead and used the little “edit pencil” on the title of the thread to move it to DLS Course 1.