代码之家  ›  专栏  ›  技术社区  ›  Medulla Oblongata

不完整的gamma函数不接受复杂的值输入

  •  3
  • Medulla Oblongata  · 技术社区  · 7 年前

    我正在计算 upper incomplete gamma function 定义类似于 this post . 如果我使用

    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''
    

    是否有其他函数来进行计算?当我试着用Wolframalpha做这个的时候,似乎没有问题。 Gamma 功能。

    1 回复  |  直到 7 年前
        1
  •  2
  •   user6655984    7 年前

    mpmath

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

    Wolfram Alpha

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

    0 mpmath.gammainc mpc