Skip to content
DeepForgeby svx
All problems
EasyCalculusca-276

Leaky ReLU Derivative Vector

Problem

The leaky ReLU is f(z) = z for z > 0 and f(z) = alpha * z otherwise, with derivative 1 for positive inputs and alpha elsewhere.

Given a list of pre-activations and alpha (default 0.01), return the derivative for each entry.

Hint

The derivative is piecewise constant; zero takes the negative branch.

Test cases

case 1
in: [[1,-2,3,0]]
expected: [1,0.01,1,0.01]
case 2
in: [[-1,-1]]
expected: [0.01,0.01]
case 3
in: [[0.5,0,-0.5],0.1]
expected: [1,0.1,0.1]
Starter codePython
def leaky_relu_derivative(values, alpha=0.01):
    # Your code here
    pass

3 test cases · run your code against them in the editor