Saturday, 26 January 2019

How to represent multiple level combinations?

The book Introduction to Probability by Blitzstein and Hwang provides an example of combinations using ice cream.

  • The first level is cone: Waffle or Cake
  • The second level is flavour: chocolate, vanilla or strawberry

The basic example is 2 * 3 = 6 separate choices.

I can represent each level of choice separately:

from sympy.functions.combinatorial.numbers import nC
from sympy.utilities.iterables import combinations, combinations_with_replacement

cones = combinations('CW', 1)
list(cones)
>>> [('C',), ('W',)]

flavours = combinations('cvs', 1)
list(flavours)
>>> [('c',), ('v',), ('s',)]

# how to get a list representing all choices? (Cc, Cv, Cs, Wc, Wv, Ws)

# how to return a count of the choices, e.g. with nC()?

I was wondering if it is possible to combine the levels with sympy and return a list of each combination and a count of the available combinations?



from How to represent multiple level combinations?

No comments:

Post a Comment