[Numpy-discussion] lists of zeros and ones

Joe Kington jkington@wisc....
Fri Mar 19 10:21:19 CDT 2010


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, 0, 0, 1),
     (1, 0, 1, 0),
     (1, 1, 0, 0)])


On Fri, Mar 19, 2010 at 10:17 AM, Joe Kington <jkington@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, 0),
>  (1, 1, 0, 0),
>  (1, 0, 1, 0),
>  (1, 0, 0, 1),
>  (1, 0, 1, 0),
>  (1, 0, 0, 1),
>  (0, 1, 1, 0),
>  (0, 1, 0, 1),
>  (0, 1, 1, 0),
>  (0, 1, 0, 1),
>  (0, 0, 1, 1),
>  (0, 0, 1, 1),
>  (0, 1, 1, 0),
>  (0, 1, 0, 1),
>  (0, 1, 1, 0),
>  (0, 1, 0, 1),
>
>
>
>  (0, 0, 1, 1),
>  (0, 0, 1, 1)]
>
> Hope that helps,
> -Joe
>
> On Fri, Mar 19, 2010 at 9:53 AM, gerardob <gberbeglia@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
>> numpy.eye(n,dtype=int).tolist()
>>
>> 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]]
>>
>> Any ideas?
>> Thanks.
>>
>>
>>
>>
>>
>>
>>
>> --
>> View this message in context:
>> http://old.nabble.com/lists-of-zeros-and-ones-tp27950978p27950978.html
>> Sent from the Numpy-discussion mailing list archive at Nabble.com.
>>
>> _______________________________________________
>> NumPy-Discussion mailing list
>> NumPy-Discussion@scipy.org
>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>>
>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20100319/999fd96c/attachment-0001.html 


More information about the NumPy-Discussion mailing list