Skip to content
DeepForgeby svx
All problems
EasyDeep Learningdl-006

Leaky ReLU

Problem

Apply the leaky ReLU activation element-wise to a list: f(x) = x if x > 0, else alpha * x.

The signature is leaky_relu(x, alpha=0.01). Return a new list of the same length.

Hint

Compare each value against zero and multiply the negatives by alpha.

Test cases

case 1
in: [[-2,-1,0,1,2],0.01]
expected: [-0.02,-0.01,0,1,2]
case 2
in: [[-4,4],0.1]
expected: [-0.4,4]
case 3
in: [[0],0.5]
expected: [0]
case 4
in: [[-0.5,0.5]]
expected: [-0.005,0.5]
Starter codePython
def leaky_relu(x, alpha=0.01):
    # Your code here
    pass

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