Implement the Leaky ReLU activation function:
f(x)={xαxx≥0x<0Here, α is the slope applied to negative inputs. Return a NumPy array for a scalar, list, or NumPy-array input.
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]
np.asarray(x, dtype=float) preserves the input shape as an array.
np.where(x >= 0, x, alpha * x) applies both branches elementwise.
Sign in to take notes on this problem
Accepts: array
Accepts: number
Implement the Leaky ReLU activation function:
f(x)={xαxx≥0x<0Here, α is the slope applied to negative inputs. Return a NumPy array for a scalar, list, or NumPy-array input.
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]
np.asarray(x, dtype=float) preserves the input shape as an array.
np.where(x >= 0, x, alpha * x) applies both branches elementwise.
Sign in to take notes on this problem
Accepts: array
Accepts: number