numpy permutations with replacement

Mensanator mensanator at aol.com
Mon Apr 13 19:17:02 CEST 2009


On Apr 13, 6:36 am, "skorpi... at gmail.com" <skorpi... at gmail.com> wrote:
> On Apr 13, 7:13 am, Chris Rebert <c... at rebertia.com> wrote:
>
>
>
>
>
> > On Mon, Apr 13, 2009 at 4:05 AM, skorpi... at gmail.com
>
> > <skorpi... at gmail.com> wrote:
> > > 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
>
> > --
> > I have a blog:http://blog.rebertia.com
>
> 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]





More information about the Python-list mailing list