Implement the Leaky ReLU activation function. Unlike standard ReLU which outputs 0 for negative inputs, Leaky ReLU allows a small, non-zero gradient (controlled by parameter alpha) for negative values.
import numpy as np
def leaky_relu(z, alpha=0.01):
z = np.array(z, dtype=np.float64)
return np.where(z > 0, z, alpha * z).tolist()np.where to select: if the element is positive, keep it; otherwise multiply by alpha.