n-dim permutation matrix/generator?
anton.vredegoor at gmail.com
Mon Nov 20 15:26:33 CET 2006
> for the purpose of flat n-dim iteration a function or generator
> ndim_permute(*v) should compute or generate a list of tuples like:
> ndim_permute( (0,1,2), (0,1), (0,1), ) ->
> 0 0 0
> 0 0 1
> 0 0 2
> 0 1 0
> 0 1 1
> 0 1 1
hmm ... shouldn't his be (0 1 2) ?
> 1 0 1
> what is a good solution? Or is there already a total iterator existing
> somewhere in the stdlib?
I think there are good solutions in the python cookbook at:
But it gives a page mentioning 'system difficulties' now, so I can't
check. Someone else will post the link to their favorite recipe.
Meanwhile, this gives me a chance to plug some of my experimental code :-)
for x in seq:
for dummy in xrange(n):
p,R = 1,
for arg in args:
L = list(arg)
p *= len(L)
for dummy in xrange(p):
yield tuple(x.next() for x in R)
for x in cross((0,1,2), (0,1), (0,1)):
More information about the Python-list