scipy.special.log_softmax¶
- scipy.special.log_softmax(x, axis=None)[源代码]¶
Softmax函数的对数::
log_softmax(x) = log(softmax(x))
- 参数
- xarray_like
输入数组。
- axis整型或整型元组,可选
轴以沿其计算值。默认值为None,将计算整个阵列的Softmax x 。
- 退货
- sndarray或标量
具有与相同形状的数组 x 。结果的指数沿指定轴的总和为1。如果 x 是标量,则返回标量。
注意事项
log_softmax
比起现在的情况要准确得多np.log(softmax(x))
其输入可使softmax
饱和(参见下面的示例)。1.5.0 新版功能.
示例
>>> from scipy.special import log_softmax >>> from scipy.special import softmax >>> np.set_printoptions(precision=5)
>>> x = np.array([1000.0, 1.0])
>>> y = log_softmax(x) >>> y array([ 0., -999.])
>>> with np.errstate(divide='ignore'): ... y = np.log(softmax(x)) ... >>> y array([ 0., -inf])