x1def softmax1(x):2 '''3 原始softmax4 '''5 f_x = np.exp(x) / np.sum(np.exp(x))6 return f_x7
8
9def softmax2(x):10 '''11 优化版softmax12 '''13 y = np.exp(x - np.max(x))14 f_x = y / np.sum(y)15 return f_x16
17softmax2([1, 20, 300000])