def binomial(n):
'''
Return all binomial coefficents for a given order.
For n > 5, scipy.special.binom is used, below we hardcode
to avoid the scipy.special dependancy.
'''
if n == 1: return [1,1]
elif n == 2: return [1,2,1]
elif n == 3: return [1,3,3,1]
elif n == 4: return [1,4,6,4,1]
elif n == 5: return [1,5,10,10,5,1]
else:
from scipy.special import binom
return binom(n,np.arange(n+1))
评论列表
文章目录