当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Python sympy.binomial_coefficients()用法及代码示例


借助于sympy.binomial_coefficients()方法,我们可以找到给定整数的二项式系数。该方法返回包含对的字典{(k1, k2) : C_kn}哪里C_kn是二项式系数,n=k1+k2

用法: binomial_coefficients(n)

参数:
n - 它表示一个整数。


返回:返回包含对(k1,k2)的字典:Ckn哪里Ckn是二项式系数,n = k1 + k2。

范例1:

# import binomial_coefficients() method from sympy 
from sympy.ntheory import binomial_coefficients 
  
n = 6
  
# Use binomial_coefficients() method  
binomial_coefficients_n = binomial_coefficients(n)  
      
print("binomial_coefficients({}) = {} ".format(n, binomial_coefficients_n))

输出:

binomial_coefficients(6) = {(3, 3): 20, (1, 5): 6, (6, 0): 1, (0, 6): 1, (4, 2): 15, (5, 1): 6, (2, 4): 15}

范例2:

# import binomial_coefficients() method from sympy 
from sympy.ntheory import binomial_coefficients 
  
n = 9
  
# Use binomial_coefficients() method  
binomial_coefficients_n = binomial_coefficients(n)  
      
print("binomial_coefficients({}) = {} ".format(n, binomial_coefficients_n))

输出:

binomial_coefficients(9) = {(2, 7): 36, (9, 0): 1, (8, 1): 9, (5, 4): 126, (6, 3): 84, (4, 5): 126, (1, 8): 9, (3, 6): 84, (0, 9): 1, (7, 2): 36} 


相关用法


注:本文由纯净天空筛选整理自rupesh_rao大神的英文原创作品 Python | sympy.binomial_coefficients() method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。