Derivative of the Sigmoid

~12 mincode completion

Implement sigmoid_derivative(z) for an array z, returning elementwise as an array.

Examples

The derivative peaks at zero, where it equals a quarter

Input
sigmoid_derivative([0])
Output
[0.25]

It is symmetric: +2 and -2 shrink the gradient identically

Input
sigmoid_derivative([-2, 0, 2])
Output
[0.10499, 0.25, 0.10499]

A saturated unit has almost no gradient left

Input
sigmoid_derivative([6, -6])
Output
[0.00247, 0.00247]

Hints

Hint 1

applies elementwise, so negate the whole array and exponentiate it in one go.

Hint 2

A common slip here: returns sigma instead of its derivative.

Requirements

  • z: array of pre-activations, any shape

  • Return array of the same shape: sigma(z) * (1 - sigma(z))

Constraints

  • Allowed library: NumPy only

  • Time limit: 200 ms, Memory: 64 MB

Where this shows up

~12 min

4 employers weight this skill

4 quant funds. Top match scores 93.

Python
import numpy as np


def sigmoid_derivative(z):
    """
    Elementwise derivative of the logistic sigmoid.

    Args:
        z: array of pre-activations, any shape

    Returns:
        array of the same shape: sigma(z) * (1 - sigma(z))
    """
    # YOUR CODE HERE
    pass
Loading docs…

The AI Mentor needs an account

It reads your code and the failing tests and nudges you toward the fix without handing you the answer. Free accounts get it on every problem you're working on today.