首页 > 解决方案 > 有没有像张量流中那样的cumulative_logsumexp 的numpy 模拟?

问题描述

我想知道https://www.tensorflow.org/api_docs/python/tf/math/cumulative_logsumexp这个函数在 tensorflow 中是否有一个 numpy 模拟?

标签: numpy

解决方案


np.logaddexp.accumulate. 例如:

>>> np.logaddexp.accumulate(np.arange(7))
array([0.        , 1.31326169, 2.40760596, 3.4401897 , 4.4519144 ,
       5.45619332, 6.45776285])

# verify:
>>> np.exp(_)
array([  1.        ,   3.71828183,  11.10733793,  31.19287485,
        85.79102488, 234.20418399, 637.63297748])
>>> np.diff(_)
array([  2.71828183,   7.3890561 ,  20.08553692,  54.59815003,
       148.4131591 , 403.42879349])
>>> np.log(_)
array([1., 2., 3., 4., 5., 6.])

推荐阅读