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,
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
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
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
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),
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
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):
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
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
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
10 matches
Mail list logo