Sigmoid Function

~10 mincode completion

Implement that applies the sigmoid function element-wise.

Examples

z=0 gives exactly 0.5

Input
sigmoid(0)
Output
0.5

Large positive z approaches 1

Input
sigmoid(100)
Output
1

Large negative z approaches 0

Input
sigmoid(-100)
Output
0

Hints

Hint 1

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

Hint 2

Do not forget to negation in exp. That step is easy to skip.

Requirements

  • z: Scalar or NumPy array

  • Return Values in (0, 1), same shape as z.

Constraints

  • Allowed library: NumPy only

  • Time limit: 200 ms, Memory: 64 MB

Where this shows up

~10 min

7 employers weight this skill

2 health and bio companies, 2 quant funds, 2 enterprise vendors, 1 AI product company. Top match scores 87.

Python
import numpy as np

def sigmoid(z):
    """
    Apply the sigmoid function element-wise.

    Args:
        z: Scalar or NumPy array

    Returns:
        Values in (0, 1), same shape as 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.