Swish: Each Input Times Its Own Sigmoid

Activation FunctionsEasy+10 XP+10

Swish: Each Input Times Its Own Sigmoid

ReLU has a hard corner at zero — its gradient jumps abruptly from 0 to 1. Swish smooths that out by weighting each input by its own sigmoid, giving a curve that dips slightly negative before rising, instead of clamping flat to zero:

swish(x)=x⋅σ(x)=x1+e−x\text{swish}(x) = x \cdot \sigma(x) = \frac{x}{1 + e^{-x}}swish(x)=x⋅σ(x)=1+e−xx​

Task: write swish(values) applying this element-wise, rounded to 4 decimal places.

  • Unlike ReLU, Swish is not zero for every negative input — it dips slightly below zero before flattening out.
  • Zero maps to exactly zero, since σ(0) = 0.5 and 0 × 0.5 = 0.

Examples

values = [-2.0, -0.5, 0.0, 1.5, 3.0]
returns [-0.2384, -0.1888, 0.0, 1.2264, 2.8577]
values = [-10.0, 10.0]
returns [-0.0005, 9.9995]

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