scipy 中不完整的 Gamma 函数 [英] Incomplete Gamma function in scipy
问题描述
我想计算 wolfram alpha 调用的不完全伽马函数
根据 http://mathworld.wolfram.com/IncompleteGammaFunction.html,这是上不完全伽马函数,而 Scipy 输出的是 WolframAlpha 称为下不完全伽马函数的缩放版本.通过使用等式 10 中的恒等式,可以看到在 a>0 的情况下,您可以使用以下内容:
from scipy.special import gammainc来自 scipy.special 导入伽马伽马(0.01)*(1 - 伽马inc(0.01,0.1))
与 WolframAlpha 一致返回 1.8032413569025461
.
简而言之,WolframAlpha 中的 Gamma[a,x]
对应于 Scipy 中的 gamma(a)*(1-gammainc(a,x))
,前提是a>0
.
I would like to compute what wolfram alpha calls the incomplete gamma function (see here):
`gamma[0, 0.1]`
The wolfram alpha output is 1.822
. The only thing scipy
gives me that resembles this is scipy.special.gammainc
, but it has a different definition than how wolfram alpha defines their incomplete gamma function.
Not surprisingly
import scipy
scipy.special.gammainc(0, 0.1)
gives me nan
. Does scipy
support what I'm looking for?
According to http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.special.gammainc.html, the first argument must be positive, whereas you have zero; that's why you're getting NaN.
That said, suppose we try to compute Gamma[0.01,0.1]
instead. In this case WolframAlpha returns 1.80324
:
According to http://mathworld.wolfram.com/IncompleteGammaFunction.html, this is the Upper Incomplete Gamma Function, whereas what Scipy outputs is a scaled version of what WolframAlpha calls the Lower Incomplete Gamma Function. By using the identity in Equation 10, one can see that in cases where a>0, you can use the following:
from scipy.special import gammainc
from scipy.special import gamma
gamma(0.01)*(1 - gammainc(0.01,0.1))
which returns 1.8032413569025461
in agreement with WolframAlpha.
In short, Gamma[a,x]
in WolframAlpha corresponds to gamma(a)*(1-gammainc(a,x))
in Scipy, provided that a>0
.
这篇关于scipy 中不完整的 Gamma 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!