# Course 1 week 2 practice exercise , basic_sigmoid

In the basic sigmoid exercise I get these notes even though there’s an output, I’m not sure how to figure out my mistake and correct it

Well, let’s start by working out what the value of sigmoid(1) should be. According to the mathematical formula, that would be:

sigmoid(1) = \displaystyle \frac {1}{1 + e^{-1}}

e^{-1} = \frac {1}{e} = 0.367879
1 + e^{-1} = 1.367879
\displaystyle \frac {1}{1 + e^{-1}} = 0.731059

So sigmoid(1) should be around 0.731059. It looks like your code generated a value of 0.26894… That is not close to the correct value, so I’m not sure what to say. The only thing I can suggest is to start by examining the formula for sigmoid again. Here it is:

sigmoid(x) = \displaystyle \frac {1}{1 + e^{-x}}

So what does your code do and why does it not generate the correct result?

Actually I have a theory: I think your code probably computes this formula instead:

\displaystyle \frac {1}{1 + e^{x}}

That is not the same as the specified formula for sigmoid. That formula would give the value 0.26894… for the input value of x = 1.

Thank you so much this was actually my mistake I didn’t type -x which gave me the wrong output, thank you again!

Thank you for the answer, and I would like to ask one more question,
“”"
Compute sigmoid of x.

Arguments:
x -- A scalar

Return:
s -- sigmoid(x)
"""


What does this mean in red color? are they also part of the code?

I don’t see anything red in your post, but what you are showing is what is called a “docstring” in python. It is a fancy kind of a comment that just shows you what the inputs and outputs of the function are. Comments don’t actually get executed, so the only way that they matter is for informational purposes. Another form of documentation basically.

The format of a docstring is that it starts and ends with three quotion marks on a line by themselves. This is just to help with the multiline nature of docstrings. Doing a multiline comment as complex as the typical docstring using the normal # characters is a bit tedious.

1 Like