softmax 函数,被称为 归一化指数函数,是sigmoid函数的推广. 它将向量等比压缩到[0, 1]之间,所有元素和为1. 图解: Example: softmax([1, 2, 3, 4, 1, 2, 3]) = [0.024, 0.064, 0.175, 0.475, 0.024, 0.064, 0.175] Code: import numpy as np def softmax(x): c = np.max(x, axis = x.ndim - 1, keepdims = True