Week 1 Assignment1 Softmax function

In provided Softmax function (file: rnn_utils.py)
Why is it e_x = np.exp(x - np.max(x))?
Shouldn’t it be just e_x = np.exp(x)?
Why np.max(x) is subtracted from x?

Hi @sahildatamaster, the subtraction is for numerical stability in case the numbers get big. We do not want to be getting infinity while taking the exponents. Also, it does not affect the final calculation since the calculation is normalized.

3 Likes

Thanks, Noted!