bliswell
bliswell

Reputation: 101

Python permutate to create arrays

I want a function in Python that generates all permutations of a possible array, where the unique outputs have the following form and constraints:

I know of the itertools and combinations/products modules.

I could use "products" for arrangements of the 6 possible columns, 1: (1 0 0). .... 6: (0 0 -1), but the row sum constraint wouldn't be satisfied.

Plus starting with all possible combinations/products and filtering out the unwanted means starting with an excessively large set. It would be better if the initial set followed the rules to begin with.

Upvotes: 0

Views: 64

Answers (1)

kabanus
kabanus

Reputation: 25895

Seems like you are looking for combinations_with_replacement:

[np.array(c).T for c in combinations_with_replacement(((0, 0, 1), (0, 1, 0), (1, 0, 0)), N)]

This will create a sorted list of all possible such matrices with N columns. Note this is a lot of arrays for N=63, 2080 to be exact. You can also make this a 3D array directly.

Upvotes: 1

Related Questions