Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在估计两个伽马函数的比率。gamma(x)和的两个估计值gamma(y)都非常大(> 10^300),但两者的比例应该相当小。
gamma(x)
gamma(y)
from scipy.special import gamma gamma(x) / gamma(y)
不幸的是,有一个点gamma(x)太大并且 scipy 返回一个inf值。有没有办法阻止这种情况,增加阈值,或者计算这个比率?
inf
谢谢
假设 x 和 y 是实数和正数,您可以使用以下恒等式:
a / b = e^(ln(a) - ln(b))
我可以建议gmpy2用于任意精度计算。它有gmpy2.lgamma,它返回 gamma 函数的对数,您可以使用gmpy2.exp它从对数形式转换为所需的比率。
gmpy2
gmpy2.lgamma
gmpy2.exp