#185Sigmoid derivative from the activationEasy

Sigmoid derivative from the activation

Background

The lesson uses sigmoid everywhere partly because its derivative has a tidy form that reuses the value you already computed:

σ(z)=σ(z)(1σ(z))=a(1a)\sigma'(z) = \sigma(z)\bigl(1 - \sigma(z)\bigr) = a\,(1 - a)

where a=σ(z)a = \sigma(z) is the activation from the forward pass. So once you've cached aa, you get the local gradient for free — no need to recompute the exponential.

Problem statement

Implement sigmoid_prime(a) that, given the sigmoid activation a (not the pre-activation zz), returns σ(z)=a(1a)\sigma'(z) = a(1-a) elementwise.

Input

  • a — array-like (or scalar) of sigmoid activations, each in (0,1)(0, 1).

Output

Returns an np.ndarray (same shape as a) of local gradients a(1a)a(1-a).

Examples

Example 1 — steepest at 0.5

Input:  a = 0.5
Output: 0.25

Explanation: 0.5×0.5=0.250.5\times0.5 = 0.25, the maximum slope of the sigmoid (at z=0z=0).

Example 2 — saturated activations have tiny gradient

Input:  a = [0.5, 0.99, 0.01]
Output: [0.25   0.0099 0.0099]

Explanation: near 0 or 1 the slope collapses — the vanishing-gradient regime.

Constraints

  • Use the cached form a * (1 - a) — do not take an exponential.
  • Return an np.ndarray.

Notes

  • This is the factor the backward pass multiplies by at every sigmoid; it's largest at a=0.5a=0.5 and near zero when the unit saturates.
Python
Loading...

▶ Run executes the 3 visible sample tests below in your browser. Submit runs the full suite — including hidden tests — on the server for an official verdict.

  • Maximum slope at a = 0.5 (example)
  • Saturated units shrink (reference)
  • Matches the z-form on a sample vector