Implement the Sigmoid Function

Neural NetworksEasy+10 XP+10

Implement the Sigmoid Function

The sigmoid function squashes any real number into the range (0, 1) — it's the classic activation function that turns a raw score into something that looks like a probability.

Formula: sigmoid(x) = 1 / (1 + e^-x)

Task: write a function sigmoid(x) that takes a single number x and returns sigmoid(x), rounded to 4 decimal places.

  • Use math.exp for e^x.
  • Large positive or negative inputs should still return a value strictly between 0 and 1.

Sigmoid

σ(x) = 1 / (1 + e⁻ˣ) — squeezes everything into (0, 1).

x0.5
σ(0.5) = 0.622

Examples

x = 0
returns 0.5
x = 2
returns 0.8808

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run