numpy permutations with replacement

S

skorpio11

I am trying to generate all possible permutations of length three from
elements of [0,1]. i.e in this scenario there are a total of 8
distinct permutations:

[0,0,0]
[0,0,1]
[0,1,0]
.
.
.
[1,1,1]


Does numpy define a function to achieve this ?

Thanks in advance
 
C

Chris Rebert

I am trying to generate all possible permutations of length three from
elements of [0,1]. i.e in this scenario there are a total of 8
distinct permutations:

[0,0,0]
[0,0,1]
[0,1,0]
   .
   .
   .
[1,1,1]


Does numpy define a function to achieve this ?

No idea, but the Python standard library already has this covered with
itertools.permutations()
[http://docs.python.org/library/itertools.html].

Cheers,
Chris
 
S

skorpio11

I am trying to generate all possible permutations of length three from
elements of [0,1]. i.e in this scenario there are a total of 8
distinct permutations:
[0,0,0]
[0,0,1]
[0,1,0]
   .
   .
   .
[1,1,1]
Does numpy define a function to achieve this ?

No idea, but the Python standard library already has this covered with
itertools.permutations()
[http://docs.python.org/library/itertools.html].

Cheers,
Chris

Thanks Chris,

That looks promising, however I am still stuck at python 2.5 (I need
numpy). And the 2.5 version does not look as nice as the 2.6 itertool.
So, if there is a numpy method ... please let me know ..
 
M

Mensanator

I am trying to generate all possible permutations of length three from
elements of [0,1]. i.e in this scenario there are a total of 8
distinct permutations:
[0,0,0]
[0,0,1]
[0,1,0]
   .
   .
   .
[1,1,1]
Does numpy define a function to achieve this ?
No idea, but the Python standard library already has this covered with
itertools.permutations()
[http://docs.python.org/library/itertools.html].
Cheers,
Chris

Thanks Chris,

That looks promising, however I am still stuck at python 2.5 (I need
numpy). And the 2.5 version does not look as nice as the 2.6 itertool.
So, if there is a numpy method ... please let me know ..

This isn't dependent on numpy or Python version:
for j in e:
for k in e:
print [i,j,k]


[0, 0, 0]
[0, 0, 1]
[0, 1, 0]
[0, 1, 1]
[1, 0, 0]
[1, 0, 1]
[1, 1, 0]
[1, 1, 1]
 
S

skorpio11

On Mon, Apr 13, 2009 at 4:05 AM, (e-mail address removed)
I am trying to generate all possible permutations of length three from
elements of [0,1]. i.e in this scenario there are a total of 8
distinct permutations:
[0,0,0]
[0,0,1]
[0,1,0]
   .
   .
   .
[1,1,1]
Does numpy define a function to achieve this ?
No idea, but the Python standard library already has this covered with
itertools.permutations()
[http://docs.python.org/library/itertools.html].
Cheers,
Chris
Thanks Chris,
That looks promising, however I am still stuck at python 2.5 (I need
numpy). And the 2.5 version does not look as nice as the 2.6 itertool.
So, if there is a numpy method ... please let me know ..

This isn't dependent on numpy or Python version:
e = [0,1]
for i in e:

        for j in e:
                for k in e:
                        print [i,j,k]

[0, 0, 0]
[0, 0, 1]
[0, 1, 0]
[0, 1, 1]
[1, 0, 0]
[1, 0, 1]
[1, 1, 0]
[1, 1, 1]

Much appreciated. This is exactly what was needed...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,602
Members
45,182
Latest member
BettinaPol

Latest Threads

Top