如何在Python中计算大整数的exp(x)?

Ear*_*nao 5 python math artificial-intelligence numpy

我在我的人工神经网络中使用了 sigmoid 函数。我传递给该函数的值范围为 10,000 到 300,000。我需要一个高精度的答案,因为它将作为我的人工神经网络中节点之间连接的权重。我尝试在 numpy 中查找但没有运气。有没有办法计算e^(-x)

Pau*_*aul 4

常规的 python math 和 numpy 模块将在 exp(300000) 上溢出。

您需要的是一个任意精度的浮点库。

先决条件:pip install mpmath

from mpmath import *
mp.dps=300
print exp(300000)
2.21090954962043147554031964344003334958746533182776533253160702399084245726328190320934903726540800347936047182773804396858994958295396516475277561815722954583856797032504775443385287094864178178111231967140927970972263439977028621274619241097429676587262948251263990280758512853239132411057394977398e+130288
Run Code Online (Sandbox Code Playgroud)

另请参阅http://code.google.com/p/mpmath/