當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。