So I'm trying to write an ELU activation function and the input into the function would be a 1D array of shape (20,1) and the output should be a similar array with the activation applied for each element in the array. The problem is that although I've done this with sigmoid or tanh and so on, for ELU we have a conditional check for the value at a given index.
def elu(x):
d=np.zeros_like(x, dtype=float)
d[x<=0]=alpha * (np.exp(x) - 1)
d[x>0]=x
return d
This is what I have so far, but it doesn't work, since I'm calling the np.exp function on an array itself, so the output would be an array, but I'm trying to assign that array value into a single element. The question is, how would I access the element that fulfilled such condition and replace it with the value of that expression, namely alpha*(np.exp(x)-1).
The alternative would be making a for loop to cycle through each element one by one to update the array or make the method work on a single scalar and then when calling the activation, cycle through the inputs and call the activation individually each time for each element (and then do the same when calling its derivative).