Counting & Binomial coefficients with scipy


My Discrete Math final is coming up on December 16. We had a midterm on Sunday, December 3. In the remaining two weeks, the class will cover 5 chapters. I am not sure how the professor will do this in our last 3 hour lecture, but he has taught this class before, so I know he has a plan.

Today I am working on Chapter 6, which covers topics like counting, the pigeonhole principle, permutations and combinations, binomial coefficients and identities and more.

Binomial coefficients are a useful concept. Today was my introduction, and it seems like there is some real life application to it. Like this r-combination example from our book: how many ways are there to choose 5 people from a team of 10? Using the theorem C(n,r) = n!/r!(n-r)!, it is C(10,5) =10!/5!5!. It can take a while to calculate multiple factorials….

In my continued quest to simplify my life while also learning new things in python, today I discovered the python scipy library. (Last week I was hooked on the sympy library and the math module in the standard library, who knows what next week will bring!) Within scipy, there is a special functions submodule, and it has a function that calculates binomial coefficients. Yay!

To solve this problem, only one line of code was required after the module was imported:

>>> import scipy.special
>>> scipy.special.binom(10,5)

While it is important to understand the concept behind binomial coefficients and all of the other mathy things my class requires, given the current time crunch, I am happy to rely on python for some assistance!


Comments are closed.

Create a free website or blog at

Up ↑