Re: How to generate (enumerate) 2**N tuples representing all vertices of unit hypercube in N-dimensional hyperspace ?

2006-01-04 Thread bonono
Dr. Colombes wrote: I'm looking for a good Python way to generate (enumerate) the 2**N tuples representing all vertices of the unit hypercube in N-dimensional hyperspace. For example, for N=4 the Python code should generate the following 2**N = 16 tuples: (1,1,1,1), (1,1,1,-1), (1,1,-1,

Re: How to generate (enumerate) 2**N tuples representing all vertices of unit hypercube in N-dimensional hyperspace ?

2006-01-04 Thread Heiko Wundram
Claudio Grondi wrote: Heiko Wundram wrote: def perm(n): return (tuple(((1,-1)[(ti)%2] for i in xrange(n))) for t in xrange(2L**n)) Isn't this kind of coding beeing the result of suffering from the post-pyContest illness syndrom? I don't think what Paul Rubin posted is the

Re: How to generate (enumerate) 2**N tuples representing all vertices of unit hypercube in N-dimensional hyperspace ?

2006-01-04 Thread Dr. Colombes
Paul, Heiko: Thank you for the quality, parsimony and promptness of your excellent suggestions. I wasn't familiar with the Python yield function. Dr. Colombes -- http://mail.python.org/mailman/listinfo/python-list

Re: How to generate (enumerate) 2**N tuples representing all vertices of unit hypercube in N-dimensional hyperspace ?

2006-01-04 Thread Claudio Grondi
Heiko Wundram wrote: Claudio Grondi wrote: Heiko Wundram wrote: def perm(n): return (tuple(((1,-1)[(ti)%2] for i in xrange(n))) for t in xrange(2L**n)) Isn't this kind of coding beeing the result of suffering from the post-pyContest illness syndrom? I don't think what Paul

How to generate (enumerate) 2**N tuples representing all vertices of unit hypercube in N-dimensional hyperspace ?

2006-01-03 Thread Dr. Colombes
I'm looking for a good Python way to generate (enumerate) the 2**N tuples representing all vertices of the unit hypercube in N-dimensional hyperspace. For example, for N=4 the Python code should generate the following 2**N = 16 tuples: (1,1,1,1), (1,1,1,-1), (1,1,-1, 1), (1,1,-1,-1),

Re: How to generate (enumerate) 2**N tuples representing all vertices of unit hypercube in N-dimensional hyperspace ?

2006-01-03 Thread Paul Rubin
Dr. Colombes [EMAIL PROTECTED] writes: I'm looking for a good Python way to generate (enumerate) the 2**N tuples representing all vertices of the unit hypercube in N-dimensional hyperspace. For example, for N=4 the Python code should generate the following 2**N = 16 tuples: Here's a

Re: How to generate (enumerate) 2**N tuples representing all vertices of unit hypercube in N-dimensional hyperspace ?

2006-01-03 Thread Heiko Wundram
Dr. Colombes wrote: Maybe converting each integer in the range(2**N) to binary, then converting to bit string, then applying the tuple function to each bit string? A direct translation of that: def perm(n): rv = [] for i in xrange(2L**n): cur = [] for j in range(n):

Re: How to generate (enumerate) 2**N tuples representing all vertices of unit hypercube in N-dimensional hyperspace ?

2006-01-03 Thread Paul Rubin
Heiko Wundram [EMAIL PROTECTED] writes: def perm(n): rv = [] for i in xrange(2L**n): cur = [] for j in range(n): cur.append(1-2*(bool(i (1j # cur is in reversed order LSB first, but as you seemingly don't # care about order of the

Re: How to generate (enumerate) 2**N tuples representing all vertices of unit hypercube in N-dimensional hyperspace ?

2006-01-03 Thread Heiko Wundram
Paul Rubin wrote: def perm(n): return [tuple([(1,-1)[(ti)%2] for i in xrange(n)]) for t in xrange(2L**n)] or replace that with: def perm(n): return (tuple(((1,-1)[(ti)%2] for i in xrange(n))) for t in xrange(2L**n)) to get a generator like in Paul's first

Re: How to generate (enumerate) 2**N tuples representing all vertices of unit hypercube in N-dimensional hyperspace ?

2006-01-03 Thread Claudio Grondi
Heiko Wundram wrote: Paul Rubin wrote: def perm(n): return [tuple([(1,-1)[(ti)%2] for i in xrange(n)]) for t in xrange(2L**n)] or replace that with: def perm(n): return (tuple(((1,-1)[(ti)%2] for i in xrange(n))) for t in xrange(2L**n)) to get a