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:
where is the activation from the forward pass. So once you've cached , 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 ), returns elementwise.
Input
a— array-like (or scalar) of sigmoid activations, each in .
Output
Returns an np.ndarray (same shape as a) of local gradients .
Examples
Example 1 — steepest at 0.5
Input: a = 0.5
Output: 0.25
Explanation: , the maximum slope of the sigmoid (at ).
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 and near zero when the unit saturates.
▶ 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