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


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


借助sympy.binomial_coefficients_list()方法,我们可以找到二项式系数作为Pascal三角形的行。

用法: binomial_coefficients_list(n)

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


返回值:返回二项式系数列表,作为Pascal三角形的行。

示例1:

# import binomial_coefficients_list() method from sympy 
from sympy.ntheory import binomial_coefficients_list 
  
n = 6
  
# Use binomial_coefficients_list() method  
binomial_coefficients_list_n = binomial_coefficients_list(n)  
      
print("{}th row of Pascal's Triangle = {} ".format(n, binomial_coefficients_list_n))

输出:

6th row of Pascal's Triangle = [1, 6, 15, 20, 15, 6, 1] 

示例2:

# import binomial_coefficients_list() method from sympy 
from sympy.ntheory import binomial_coefficients_list 
  
n = 9
  
# Use binomial_coefficients_list() method  
binomial_coefficients_list_n = binomial_coefficients_list(n)  
      
print("{}th row of Pascal's Triangle = {} ".format(n, binomial_coefficients_list_n))

输出:

9th row of Pascal's Triangle = [1, 9, 36, 84, 126, 126, 84, 36, 9, 1]  


相关用法


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