Re: [Numpy-discussion] how do I list all combinations

2007-12-30 Thread Alan G Isaac
On Wed, 26 Dec 2007, Mathew Yeates apparently wrote: > r1=["dog","cat"] > r2=[1,2] > I want to return [["dog",1],["dog",2],["cat",1],["cat",2]] This is a Cartesian product. Sage has ``cartesian_product_iterator`` for this. Also http://www.sagemath.org/doc/html/ref/module-sage.combinat.carte

Re: [Numpy-discussion] how do I list all combinations

2007-12-26 Thread Zachary Pincus
Hi all, I use numpy's own ndindex() for tasks like these: > In: numpy.ndindex? > Type: type > Base Class: > String Form: > Namespace: Interactive > File: /Library/Frameworks/Python.framework/Versions/2.4/ > lib/python2.4/site-packages/numpy/lib/index_tricks.py >

Re: [Numpy-discussion] how do I list all combinations

2007-12-26 Thread Timothy Hochberg
Here's a baroque way to do it using generated code: def cg_combinations(seqs): n = len(seqs) chunks = ["def f(%s):" % ', '.join('s%s' % i for i in range(n))] for i in reversed(range(n)): chunks.append(" " * (n -i) + "for x%s in s%s:" % (i, i)) chunks

Re: [Numpy-discussion] how do I list all combinations

2007-12-26 Thread Mathew Yeates
Thanks Chuck. Charles R Harris wrote: > > > On Dec 26, 2007 2:30 PM, Charles R Harris <[EMAIL PROTECTED] > > wrote: > > > > On Dec 26, 2007 1:45 PM, Keith Goodman <[EMAIL PROTECTED] > > wrote: > > On Dec 26, 2007 12:22 PM, Mathew

Re: [Numpy-discussion] how do I list all combinations

2007-12-26 Thread Charles R Harris
On Dec 26, 2007 2:30 PM, Charles R Harris <[EMAIL PROTECTED]> wrote: > > > On Dec 26, 2007 1:45 PM, Keith Goodman <[EMAIL PROTECTED]> wrote: > > > On Dec 26, 2007 12:22 PM, Mathew Yeates <[EMAIL PROTECTED]> wrote: > > > I have an arbitrary number of lists. I want to form all possible > > > combina

Re: [Numpy-discussion] how do I list all combinations

2007-12-26 Thread Charles R Harris
On Dec 26, 2007 1:45 PM, Keith Goodman <[EMAIL PROTECTED]> wrote: > On Dec 26, 2007 12:22 PM, Mathew Yeates <[EMAIL PROTECTED]> wrote: > > I have an arbitrary number of lists. I want to form all possible > > combinations from all lists. So if > > r1=["dog","cat"] > > r2=[1,2] > > > > I want to ret

Re: [Numpy-discussion] how do I list all combinations

2007-12-26 Thread Mathew Yeates
Which reference manual? René Bastian wrote: > Le Mercredi 26 Décembre 2007 21:22, Mathew Yeates a écrit : > >> Hi >> I've been looking at "fromfunction" and itertools but I'm flummoxed. >> >> I have an arbitrary number of lists. I want to form all possible >> combinations from all lists. So if

Re: [Numpy-discussion] how do I list all combinations

2007-12-26 Thread Mathew Yeates
yes, I came up with this and may use it. Seems like it would be insanely slow but my problem is small enough that it might be okay. Thanks Keith Goodman wrote: > On Dec 26, 2007 12:22 PM, Mathew Yeates <[EMAIL PROTECTED]> wrote: > >> I have an arbitrary number of lists. I want to form all po

Re: [Numpy-discussion] how do I list all combinations

2007-12-26 Thread Stuart Brorson
Hi -- >> I have an arbitrary number of lists. I want to form all possible >> combinations from all lists. So if >> r1=["dog","cat"] >> r2=[1,2] >> >> I want to return [["dog",1],["dog",2],["cat",1],["cat",2]] Try this: In [25]: [(x, y) for x in r1 for y in r2] Out[25]: [('dog', 1), ('dog', 2), (

Re: [Numpy-discussion] how do I list all combinations

2007-12-26 Thread René Bastian
Le Mercredi 26 Décembre 2007 21:22, Mathew Yeates a écrit : > Hi > I've been looking at "fromfunction" and itertools but I'm flummoxed. > > I have an arbitrary number of lists. I want to form all possible > combinations from all lists. So if > r1=["dog","cat"] > r2=[1,2] > > I want to return [["dog

Re: [Numpy-discussion] how do I list all combinations

2007-12-26 Thread Charles R Harris
On Dec 26, 2007 1:22 PM, Mathew Yeates <[EMAIL PROTECTED]> wrote: > Hi > I've been looking at "fromfunction" and itertools but I'm flummoxed. > > I have an arbitrary number of lists. I want to form all possible > combinations from all lists. So if > r1=["dog","cat"] > r2=[1,2] > > I want to return

Re: [Numpy-discussion] how do I list all combinations

2007-12-26 Thread Keith Goodman
On Dec 26, 2007 12:22 PM, Mathew Yeates <[EMAIL PROTECTED]> wrote: > I have an arbitrary number of lists. I want to form all possible > combinations from all lists. So if > r1=["dog","cat"] > r2=[1,2] > > I want to return [["dog",1],["dog",2],["cat",1],["cat",2]] > > It's obvious when the number of

[Numpy-discussion] how do I list all combinations

2007-12-26 Thread Mathew Yeates
Hi I've been looking at "fromfunction" and itertools but I'm flummoxed. I have an arbitrary number of lists. I want to form all possible combinations from all lists. So if r1=["dog","cat"] r2=[1,2] I want to return [["dog",1],["dog",2],["cat",1],["cat",2]] It's obvious when the number of lists