Python| sympy.binomial() 方法
在sympy.binomial()方法的帮助下,我们可以找到从n 个不同项目中选择k个项目的方法的数量。它也经常写作nCk ,发音为“n choose k”。
(1)
Syntax: binomial(N, K)
Parameters:
N – It denotes the number of items to choose from.
K – It denotes the number of items to choose.
Returns: Returns the number of ways to choose K items from a set of N distinct items
示例 #1:
# import sympy
from sympy import *
N = 4
K = 2
print("N = {}, K = {}".format(N, K))
# Use sympy.binomial() method
comb = binomial(N, K)
print("N choose K : {}".format(comb))
输出:
N = 4, K = 2
N choose K : 6
示例 #2:
# import sympy
from sympy import *
N, K = symbols('A B')
print("N = {}, K = {}".format(N, K))
# Use sympy.binomial() method
comb = binomial(N, K)
print("N choose K : {}".format(comb))
输出:
N = A, K = B
N choose K : binomial(A, B)