← Problems

4. Sigmoid Function

EasyActivation FunctionsNeural NetworksNumPy

Implement the sigmoid activation function.

σ(x)=11+ex\sigma(x) = \frac{1}{1 + e^{-x}}

The sigmoid maps any real number to the range (0,1)(0, 1), making it useful for binary classification outputs and gates in recurrent networks.

Properties to note:

  • σ(0)=0.5\sigma(0) = 0.5
  • σ(x)1\sigma(x) \to 1 as x+x \to +\infty
  • σ(x)0\sigma(x) \to 0 as xx \to -\infty
  • σ(x)=σ(x)(1σ(x))\sigma'(x) = \sigma(x)(1 - \sigma(x))

Example

Input: x = 0 Output: 0.5 Input: x = 2 Output: ≈ 0.8808

Constraints

  • Your function should work on both scalars and NumPy arrays.
Python 3
⌘ + Enter
Run your code to see results
Ctrl + Enter