[Numpy-discussion] combinatorics

2010-03-04 Thread Ernest Adrogué
Hello everybody, Suppose I want to find all 2-digit numbers whose first digit is either 4 or 5, the second digit being 7, 8 or 9. Is there a Numpy/Scipy function to calculate that kind of combinations? I came up with this function, the problem is it uses recursion: def g(sets): if len(sets)

Re: [Numpy-discussion] combinatorics

2010-03-04 Thread Ernest Adrogué
4/03/10 @ 11:19 (+0100), thus spake Ernest Adrogué: > Hello everybody, > > Suppose I want to find all 2-digit numbers whose first digit > is either 4 or 5, the second digit being 7, 8 or 9. > Is there a Numpy/Scipy function to calculate that kind of > combinations? > > I came up with this functi

Re: [Numpy-discussion] combinatorics

2010-03-04 Thread Sam Tygier
itertools in the python standard library has what you need >>> import itertools >>> list( itertools.product([4,5], [7,8,9]) ) [(4, 7), (4, 8), (4, 9), (5, 7), (5, 8), (5, 9)] (all the itertools functions return generators, so the list() is to convert it to a list) Sam __

Re: [Numpy-discussion] combinatorics

2010-03-04 Thread Johan Grönqvist
Ernest Adrogué skrev: > Suppose I want to find all 2-digit numbers whose first digit > is either 4 or 5, the second digit being 7, 8 or 9. > > I came up with this function, the problem is it uses recursion: > [...] > In [157]: g([[4,5],[7,8,9]]) > Out[157]: [[4, 7], [4, 8], [4, 9], [5, 7], [5, 8]

Re: [Numpy-discussion] combinatorics

2010-03-04 Thread Ernest Adrogué
4/03/10 @ 12:26 (+0100), thus spake Johan Grönqvist: > Ernest Adrogué skrev: > > Suppose I want to find all 2-digit numbers whose first digit > > is either 4 or 5, the second digit being 7, 8 or 9. > > > > I came up with this function, the problem is it uses recursion: > > [...] > > In [157]: g(