Implement Leaky ReLU (with α)
Implement Leaky ReLU (with α)
The Leaky ReLU activation function is defined as:
f(x)={xaxif x≥0if x<0Examples
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
Log in to take notes on this problem
Accepts: array
Accepts: number
Implement Leaky ReLU (with α)
Implement Leaky ReLU (with α)
The Leaky ReLU activation function is defined as:
f(x)={xaxif x≥0if x<0Examples
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
Log in to take notes on this problem
Accepts: array
Accepts: number