PIXELBANKv9.1.0
Menu

Implement Leaky ReLU

Problem Statement

Implement the Leaky ReLU activation function.

Background

Leaky ReLU fixes the "dying ReLU" problem by allowing a small gradient for negative inputs:

  • f(x)=xf(x) = x if x>0x > 0
  • f(x)=α⋅xf(x) = \alpha \cdot x if x≤0x \leq 0

where α\alpha is a small constant (commonly 0.01).

Your Task

Write a function leaky_relu(values, alpha=0.01) that applies Leaky ReLU element-wise to a list of values.

Output Format

Return a list of floats with Leaky ReLU applied to each element. Round each value to 4 decimal places.

Example:

Input:
values=[-1.0, 2.0], alpha=0.1
Output:
[-0.1, 2.0]
Reasoning:

For -1.0: since -1.0 <= 0, apply alpha: 0.1 × (-1.0) = -0.1. For 2.0: since 2.0 > 0, keep as is: 2.0.

Constraints:

  • -1000 <= x <= 1000 for each element
  • 0 < alpha <= 1
  • List length: 1 to 100 elements
🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.
Implement Leaky ReLU - Easy | PixelBank