on-internet
← Community

Generate matrix indexed by combinations

Stack Overflow ·

Given two positive integers d<n, I want to generate an "n choose d" by n matrix as follows. For each set of d integers, say {a1,...,ad} , I want a row with 1's on the a1,...,ad columns. For example, if d=2 and n=4, my matrix would look like [[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'm trying to code this in Python, but I'm not sure how to start as it's hard for me to somehow come up with all the sets of d integers to then make the rows. Any help would be appreciated. Thanks!

Comments

Sign in or sign up to comment and upvote.

No comments yet.