Python SciPy Possible cases of n choose k

combinations, numpy, python, scipy

Solution

Any reason for using `scipy` and not `itertools` for this particular problem?

Looking into `itertools.combinations` or `itertools.permutations` may provide a more adequate solution.

Problem

``` a = [1, 2, 3, 4, 5, 6] # OR ! a = ['one', 'two', 'three', 'four', 'five', 'six'] ``` In this situation, I just want to know ALL possible combinations; choose k elements among a. If I use `b = scipy.misc.comb(a, 1)`, it shows: ``` b = [1, 2, 3, 4, 5, 6] ``` where bi is just ai choose 1. And it doesn't work if a is an array of strings. What I really wanted is: ``` b = [[1], [2], [3], [4], [5], [6]] # OR ! b = [['one'], ['two'], ['three'], ['four'], ['five'], ['six']] ``` which means, the possible set of 1 chosen element among elements in the array a It is very easy if I use MATLAB. But I'm trying to use SciPy stack.

Original source