def softmax(w):
"""Softmax function of given array of number w.
Parameters
----------
w: array | list
The array of numbers.
Returns
-------
dist: array
The resulting array with values ranging from 0 to 1.
"""
w = np.array(w)
maxes = np.amax(w, axis=1)
maxes = maxes.reshape(maxes.shape[0], 1)
e = np.exp(w - maxes)
dist = e / np.sum(e, axis=1, keepdims=True)
return dist
评论列表
文章目录