0

To make a long story short, I'm trying to generate all the possible permutations of a set of numpy arrays. I have three numbers [j,k,m] and I would like to specify a maximum value for each one [J,K,M]. How would I then get all the combinations of arrays under these values? How could I force the k values to always be even as well? For instance:

So with the max values set to [1,2,2], the permutations would be: [0,0,0], [0,0,1], [0,0,2], [0,2,0], [0,2,1], [0,2,2], [1,0,0], [1,0,1] ...

I realise I don't have any example to code to show but I'm afraid I have literally no idea where to start with this.

From other answers it seems like sympy would be of some use?

1 Answer 1

1

I found answer that might be interested for you here and generalised it. So you can construct list of possible values for each item like so:

X = [[0, 1], [0, 1, 2], [0, 1, 2]]

And then use:

np.array(np.meshgrid(*X)).T.reshape(-1, len(X))

Output contains 18 items that you wanted. Actually, if you have only maximum values [J, K, L], you can construct X using X = [range(J+1), range(K+1), range(L+1)]

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

1 Comment

Thanks! This is exactly the expertise that makes this site so great! I think my question was a little unclear, I needed the middle value of each array to be even but using a different solution on a different site I got what I need ed: def permute(j, k, m): a = np.stack([[i, 2*l, n] for i in range(j + 1) for l in range(k + 1) for n in range(m + 1)]) return a

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.