我想知道是否有一种快速、Pythonic的方法来计算非整数(例如3.4)的阶乘?当然,Math模块中的内置factorial()函数可用,但它只适用于整数(这里不考虑负数)。
Math
factorial()
math.gamma(x)
math.factorial(n)
math.gamma(n + 1)
在Python 2.7或3.2中,您可以使用math.gamma(x + 1)。在旧版本中,您需要使用一些外部库,如SciPy。
math.gamma(x + 1)