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.
我正在使用mpmath编写一个适合计算极小概率的二项式 beta 函数。
mpmath
我需要的大部分功能已经包含在 mpmath 中或者很容易重写。然而,可悲的是,事实scipy.misc.comb并非如此。我尝试查看源代码,但它似乎基于从我无法找到其代码的文件中导入的某些binom函数。
scipy.misc.comb
binom
在不使用 for/while 循环计算阶乘的情况下,如何重写 scipy comb 函数(或编写我自己的函数)?
好的,显然mpmath确实有一个阶乘函数,其名称看似直观,mpmath.factorial-.-
mpmath.factorial
所以我的查询的解决方案很简单:
def mp_comb(N,k): val= mpmath.factorial(N)/(mpmath.factorial(k)*mpmath.factorial(N-k)) return val