TensorTonic
Problems
Implement Leaky ReLU (with α)
Activation Functions
Easy

Implement the Leaky ReLU activation function:

f(x)={xx≥0αxx<0f(x) = \begin{cases} x & x \geq 0 \\ \alpha x & x < 0 \end{cases}f(x)={xαx​x≥0x<0​

Here, α\alphaα is the slope applied to negative inputs. Return a NumPy array for a scalar, list, or NumPy-array input.

Loading visualization...

Examples

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

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

Explanation: Nonnegative values remain unchanged, while negative values are multiplied by 0.1.

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

Output: [-0.05, 5.0]

Hint 1

np.asarray(x, dtype=float) preserves the input shape as an array.

Hint 2

np.where(x >= 0, x, alpha * x) applies both branches elementwise.

Requirements

  • Accept a scalar, list, or NumPy array
  • Apply the activation without a Python element loop
  • Support the supplied alpha value
  • Always return a NumPy array

Constraints

  • alpha is non-negative
  • Use NumPy only
Try Similar Problems
Implement Sigmoid in NumPyEasyELU ActivationEasyImplement ReLU Activation in NumPyEasySELU ActivationEasyImplement Swish Activation in NumPyEasyImplement Tanh ActivationEasyDifferentiate a Tanh ActivationEasyImplement GELU Activation in PythonMediumActivation FunctionsEasySoftmax from ScratchEasyDerivatives of Common Activation FunctionsEasyContinuity of Activation FunctionsMedium
Scratchpad

Accepts: array

Accepts: number

You must run your code first.
Implement Leaky ReLU (with α)

Implement Leaky ReLU (with α)

Activation Functions
Easy

Implement the Leaky ReLU activation function:

f(x)={xx≥0αxx<0f(x) = \begin{cases} x & x \geq 0 \\ \alpha x & x < 0 \end{cases}f(x)={xαx​x≥0x<0​

Here, α\alphaα is the slope applied to negative inputs. Return a NumPy array for a scalar, list, or NumPy-array input.

Loading visualization...

Examples

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

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

Explanation: Nonnegative values remain unchanged, while negative values are multiplied by 0.1.

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

Output: [-0.05, 5.0]

Hint 1

np.asarray(x, dtype=float) preserves the input shape as an array.

Hint 2

np.where(x >= 0, x, alpha * x) applies both branches elementwise.

Requirements

  • Accept a scalar, list, or NumPy array
  • Apply the activation without a Python element loop
  • Support the supplied alpha value
  • Always return a NumPy array

Constraints

  • alpha is non-negative
  • Use NumPy only
Try Similar Problems
Implement Sigmoid in NumPyEasyELU ActivationEasyImplement ReLU Activation in NumPyEasySELU ActivationEasyImplement Swish Activation in NumPyEasyImplement Tanh ActivationEasyDifferentiate a Tanh ActivationEasyImplement GELU Activation in PythonMediumActivation FunctionsEasySoftmax from ScratchEasyDerivatives of Common Activation FunctionsEasyContinuity of Activation FunctionsMedium
Scratchpad

Accepts: array

Accepts: number

You must run your code first.
Problems
Loading...
1 / 1