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))))

(Modify if you don't like the tuples.)
But you can use a NumPy array if you wish:

cols = list(itertools.combinations(range(n),2))
r = len(cols)
rows = np.arange(r)[:,None]
a = np.zeros((r,n),dtype=np.int_)
a[rows,cols] = 1
a.tolist()

hth,
Alan Isaac

_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to