implements the exponential linear unit or elu function the function takes a vector of k real numbers and a real number alpha as input and then applies the elu function to each element of the vector script inspired from its corresponding wikipedia article https en wikipedia orgwikirectifierneuralnetworks implements the elu activation function parameters vector the array containing input of elu activation alpha hyperparameter return elu np array the input numpy array after applying elu mathematically fx x x0 else alpha ex 1 x0 alpha 0 examples exponentiallinearunitvectornp array2 3 0 6 2 3 8 alpha0 3 array 2 3 0 6 0 25939942 0 29328877 exponentiallinearunitvectornp array9 2 0 3 0 45 4 56 alpha0 067 array0 06699323 0 01736518 0 45 0 06629904 implements the elu activation function parameters vector the array containing input of elu activation alpha hyper parameter return elu np array the input numpy array after applying elu mathematically f x x x 0 else alpha e x 1 x 0 alpha 0 examples exponential_linear_unit vector np array 2 3 0 6 2 3 8 alpha 0 3 array 2 3 0 6 0 25939942 0 29328877 exponential_linear_unit vector np array 9 2 0 3 0 45 4 56 alpha 0 067 array 0 06699323 0 01736518 0 45 0 06629904
import numpy as np


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


if __name__ == "__main__":
    import doctest

    doctest.testmod()