借助於sympy.binomial_coefficients()方法,我們可以找到給定整數的二項式係數。該方法返回包含對的字典哪裏是二項式係數,。
用法: 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}
相關用法
- Python next()用法及代碼示例
- Python os.dup()用法及代碼示例
- Python set()用法及代碼示例
- Python Decimal max()用法及代碼示例
- Python PIL ImageOps.fit()用法及代碼示例
- Python os.rmdir()用法及代碼示例
- Python sympy.det()用法及代碼示例
- Python Decimal min()用法及代碼示例
- Python os.readlink()用法及代碼示例
- Python os.writev()用法及代碼示例
- Python os.readv()用法及代碼示例
- Python PIL RankFilter()用法及代碼示例
- Python os.rename()用法及代碼示例
- Python os.sendfile()用法及代碼示例
注:本文由純淨天空篩選整理自rupesh_rao大神的英文原創作品 Python | sympy.binomial_coefficients() method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。