0

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

  • 3 rows, N columns (let's say 63)

  • Each column is all 0s except one element is either 1 or -1

  • each row sums to 0, 1 or -1

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.

1
  • I'm not clear on what you're asking. Could you provide an example? Commented Jul 5, 2020 at 5:19

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.