NumPy exp() Explained: Element-wise Exponential and Overflow

np.exp turns a large input into inf and only warns instead of raising an error. The overflow matters because it turns a softmax into NaNs, and the fix is one subtraction.

What NumPy exp computes

np.exp is a universal function, or ufunc, so it applies the same operation to every element of its input without a Python loop. Each element comes back as e raised to that value, where e is Euler’s number and equals roughly 2.718281828.