[Numpy-discussion] lists of zeros and ones

2010-03-19 Thread gerardob
Hello, i would like to produce lists of lists 1's and 0's. For example, to produce the list composed of: L = [[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]] I just need to do the following: n=4 numpy.eye(n,dtype=int).tolist() I would like to know a simple way to generate a list containing all the

Re: [Numpy-discussion] lists of zeros and ones

2010-03-19 Thread Joe Kington
See itertools.permutations (python standard library) e.g. In [3]: list(itertools.permutations([1,1,0,0])) Out[3]: [(1, 1, 0, 0), (1, 1, 0, 0), (1, 0, 1, 0), (1, 0, 0, 1), (1, 0, 1, 0), (1, 0, 0, 1), (1, 1, 0, 0), (1, 1, 0, 0), (1, 0, 1, 0), (1, 0, 0, 1), (1, 0, 1, 0), (1, 0, 0, 1),

Re: [Numpy-discussion] lists of zeros and ones

2010-03-19 Thread Keith Goodman
On Fri, Mar 19, 2010 at 7:53 AM, gerardob gberbeg...@gmail.com wrote: Hello, i would like to produce lists of lists 1's and 0's. For example, to produce the list composed of: L = [[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]] I just need to do the following: n=4

Re: [Numpy-discussion] lists of zeros and ones

2010-03-19 Thread Keith Goodman
On Fri, Mar 19, 2010 at 8:17 AM, Joe Kington jking...@wisc.edu wrote: See itertools.permutations (python standard library) e.g. In [3]: list(itertools.permutations([1,1,0,0])) Out[3]: [(1, 1, 0, 0),  (1, 1, 0, 0),  (1, 0, 1, 0),  (1, 0, 0, 1),  (1, 0, 1, 0),  (1, 0, 0, 1),  (1, 1, 0,

Re: [Numpy-discussion] lists of zeros and ones

2010-03-19 Thread Joe Kington
I just realized that permutations isn't quite what you want, as swapping the first 1 for the second 1 gives the same thing. You can use set to get the unique permutations. e.g. In [4]: set(itertools.permutations([1,1,0,0])) Out[4]: set([(0, 0, 1, 1), (0, 1, 0, 1), (0, 1, 1, 0), (1,

Re: [Numpy-discussion] lists of zeros and ones

2010-03-19 Thread Gökhan Sever
On Fri, Mar 19, 2010 at 10:17 AM, Joe Kington jking...@wisc.edu wrote: See itertools.permutations (python standard library) e.g. In [3]: list(itertools.permutations([1,1,0,0])) Out[3]: [(1, 1, 0, 0), (1, 1, 0, 0), (1, 0, 1, 0), (1, 0, 0, 1), (1, 0, 1, 0), (1, 0, 0, 1), (1, 1, 0,

Re: [Numpy-discussion] lists of zeros and ones

2010-03-19 Thread josef . pktd
On Fri, Mar 19, 2010 at 11:17 AM, Keith Goodman kwgood...@gmail.com wrote: On Fri, Mar 19, 2010 at 7:53 AM, gerardob gberbeg...@gmail.com wrote: Hello, i would like to produce lists of lists 1's and 0's. For example, to produce the list composed of: L =

Re: [Numpy-discussion] lists of zeros and ones

2010-03-19 Thread josef . pktd
On Fri, Mar 19, 2010 at 11:24 AM, josef.p...@gmail.com wrote: On Fri, Mar 19, 2010 at 11:17 AM, Keith Goodman kwgood...@gmail.com wrote: On Fri, Mar 19, 2010 at 7:53 AM, gerardob gberbeg...@gmail.com wrote: Hello, i would like to produce lists of lists 1's and 0's. For example, to produce

Re: [Numpy-discussion] lists of zeros and ones

2010-03-19 Thread Alan G Isaac
On 3/19/2010 10:53 AM, gerardob wrote: I would like to know a simple way to generate a list containing all the lists having two 1's at each element. Example, n = 4 L2 = [[1,1,0,0],[1,0,1,0],[1,0,0,1],[0,1,1,0],[0,1,0,1],[0,0,1,1]] I like list(set(itertools.permutations([1,1]+[0]*(n-2