0

I've got a n x n x 2 matrix which I want to find all possible permutations of without changing the order of elements in the 3rd dimension.
For example, if my matrix was 2 x 2 x 2 and had the following values:

[[[1,2], [3,4]],  
  [5,6], [7,8]]  

Then possible permutations would be:

[[[1,2], [3,4]],  
  [7,8], [5,6]]   

[[[3,4], [1,2]],  
  [5,6], [7,8]]   

[[[1,2], [7,8]],  
  [5,6], [3,4]] 

etc.

In other words, I want to treat the tuples as single values when finding the permutations.

1 Answer 1

1

How about something like:

import numpy as np
import itertools

arr = np.array([[[1,2], [3,4]],
                [[5,6], [7,8]]])

for p in itertools.permutations(arr.reshape(-1, 2)):
    print(np.array(p).reshape(arr.shape))
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.