leaky rectified linear unit leaky relu use case leaky relu addresses the problem of the vanishing gradient for more detailed information you can refer to the following link https en wikipedia orgwikirectifierneuralnetworksleakyrelu implements the leakyrelu activation function parameters vector np ndarray the input array for leakyrelu activation alpha float the slope for negative values returns np ndarray the input array after applying the leakyrelu activation formula fx x if x 0 else fx alpha x examples leakyrectifiedlinearunitvectornp array2 3 0 6 2 3 8 alpha0 3 array 2 3 0 6 0 6 1 14 leakyrectifiedlinearunitnp array9 2 0 3 0 45 4 56 alpha0 067 array0 6164 0 0201 0 45 0 30552 implements the leakyrelu activation function parameters vector np ndarray the input array for leakyrelu activation alpha float the slope for negative values returns np ndarray the input array after applying the leakyrelu activation formula f x x if x 0 else f x alpha x examples leaky_rectified_linear_unit vector np array 2 3 0 6 2 3 8 alpha 0 3 array 2 3 0 6 0 6 1 14 leaky_rectified_linear_unit np array 9 2 0 3 0 45 4 56 alpha 0 067 array 0 6164 0 0201 0 45 0 30552
import numpy as np


def leaky_rectified_linear_unit(vector: np.ndarray, alpha: float) -> np.ndarray:
    
    return np.where(vector > 0, vector, alpha * vector)


if __name__ == "__main__":
    import doctest

    doctest.testmod()