Python | sympy.binomial_coefficients() method

With the help of sympy.binomial_coefficients() method, we can find binomial coefficients for a given integer. The method returns a dictionary containing pairs {(k1, k2) : C_kn} where C_kn are binomial coefficients and n=k1+k2.

Syntax: binomial_coefficients(n)

Parameter:
n – It denotes an integers.



Returns: Returns a dictionary containing pairs (k1, k2) : Ckn where Ckn are binomial coefficients and n = k1 + k2.

Example #1:

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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))

chevron_right


Output:

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

Example #2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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))

chevron_right


Output:

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} 


My Personal Notes arrow_drop_up

Coder Machine Learner Social Activist Vocalist

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.