python中不完整的伽马函数? [英] incomplete gamma function in python?

查看:204
本文介绍了python中不完整的伽马函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

scipy.special.gammainc 不能为第一个参数取负值.python中还有其他实现吗?我肯定可以进行手动集成,但我想知道是否已经存在好的替代方案.

正确结果:1 - Gamma[-1,1] = 0.85使用 Scipy:scipy.special.gammainc(-1​​, 1) = 0

谢谢.

解决方案

我通常会使用 mpmath 每当我需要特殊功能并且不太关心性能时.(尽管它在很多情况下的表现还是相当不错的.)

例如:

<预><代码>>>>导入 mpmath>>>mpmath.gammainc(-1​​,1)mpf('0.14849550677592205')>>>1-mpmath.gammainc(-1​​,1)mpf('0.85150449322407795')>>>mpmath.mp.dps = 50 # 任意精度!>>>1-mpmath.gammainc(-1​​,1)mpf('0.85150449322407795208164000529866078158523616237514084')

the scipy.special.gammainc can not take negative values for the first argument. Are there any other implementations that could in python? I can do a manual integration for sure but I'd like to know if there are good alternatives that already exist.

Correct result: 1 - Gamma[-1,1] = 0.85

Use Scipy: scipy.special.gammainc(-1, 1) = 0

Thanks.

解决方案

I typically reach for mpmath whenever I need special functions and I'm not too concerned about performance. (Although its performance in many cases is pretty good anyway.)

For example:

>>> import mpmath
>>> mpmath.gammainc(-1,1)
mpf('0.14849550677592205')
>>> 1-mpmath.gammainc(-1,1)
mpf('0.85150449322407795')
>>> mpmath.mp.dps = 50 # arbitrary precision!
>>> 1-mpmath.gammainc(-1,1)
mpf('0.85150449322407795208164000529866078158523616237514084')

这篇关于python中不完整的伽马函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆