5

我正在尝试计算像这篇文章中定义的上不完全伽马函数。如果我使用

from scipy.special import gamma,gammainc
from numpy import linspace

a = 0
z = (2+3j)*np.linspace(0,10)
gamma(a)*(1-gammainc(a,z))

z我得到一个错误的复数向量在哪里

TypeError: ufunc 'gammainc' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

是否有替代功能来进行计算?Gamma当我尝试使用 WolframAlpha 的函数执行此操作时,似乎没有问题。

4

1 回答 1

4

当 SciPy 不足以处理棘手的特殊功能时,mpmath通常会提供帮助。相比

>>> mpmath.gammainc(0, 2+3j)
mpc(real='-0.024826207944199364', imag='0.020316674911044622')

同样来自Wolfram Alpha

用 Python 编写,比 SciPy 慢;它也没有矢量化。因此,使用您的数据,它会像

import mpmath
result = np.array([mpmath.gammainc(w) for w in z[1:]], dtype=np.complex)

请注意,我避免0作为参数传递(它是一个极点)。的返回类型mpmath.gammainc是它自己的mpc对象类型,但可以像上面那样转换回 NumPy。

于 2018-07-31T15:50:36.377 回答