TensorTonicTensorTonic
Problems
Study PlansProjectsInterviewPricingFeedback
Problems
Loading...
1 / 1

Implement Leaky ReLU (with α)

Activation Functions
Easy

The Leaky ReLU activation function is defined as:

f(x)={xif x≥0axif x<0f(x) = \begin{cases} x & \text{if } x \geq 0 \\ ax & \text{if } x < 0 \end{cases}f(x)={xax​if x≥0if x<0​
Loading visualization...

Examples

Input: x = [-2, -1, 0, 1, 2], alpha = 0.1

Output: [-0.2, -0.1, 0.0, 1.0, 2.0]

Input: x = [-5, 5], alpha = 0.01

Output: [-0.05, 5.0]

Hint 1

Convert the input to a NumPy array first using np.asarray()

Hint 2

Use np.where(condition, value_if_true, value_if_false) for element-wise conditional operations.

Requirements

  • Input can be Python list, scalar, or NumPy array. Always return a NumPy array
  • Must be vectorized (no explicit element loops)
  • Must support custom alpha values

Constraints

  • Time ≤ 200 ms; Memory ≤ 64 MB
Try Similar Problems
Relu ActivationElu ActivationSelu ActivationSigmoid NumpySwish Activation

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

Accepts: number

You must run your code first.
PrevNext

Implement Leaky ReLU (with α)

Activation Functions
Easy

The Leaky ReLU activation function is defined as:

f(x)={xif x≥0axif x<0f(x) = \begin{cases} x & \text{if } x \geq 0 \\ ax & \text{if } x < 0 \end{cases}f(x)={xax​if x≥0if x<0​
Loading visualization...

Examples

Input: x = [-2, -1, 0, 1, 2], alpha = 0.1

Output: [-0.2, -0.1, 0.0, 1.0, 2.0]

Input: x = [-5, 5], alpha = 0.01

Output: [-0.05, 5.0]

Hint 1

Convert the input to a NumPy array first using np.asarray()

Hint 2

Use np.where(condition, value_if_true, value_if_false) for element-wise conditional operations.

Requirements

  • Input can be Python list, scalar, or NumPy array. Always return a NumPy array
  • Must be vectorized (no explicit element loops)
  • Must support custom alpha values

Constraints

  • Time ≤ 200 ms; Memory ≤ 64 MB
Try Similar Problems
Relu ActivationElu ActivationSelu ActivationSigmoid NumpySwish Activation

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

Accepts: number

You must run your code first.