2020-12-29

Generate all permutations of n entries in a w x h matrix

I'd like to generate all the permutations of n entries in a w x h matrix: example with a 2x2 matrix and n = 1:

| 1 0 |
| 0 0 |

| 0 1 |
| 0 0 |

| 0 0 |
| 1 0 |

| 0 0 |
| 0 1 |

example with a 3x3 matrix and n = 2 (partial):

| 0 0 1|
| 0 0 1|
| 0 0 0|

| 1 0 0|
| 0 0 1|
| 0 0 0|

...

I would like to avoid the usage of numpy, so I think itertool is the way to go. I am looking at one dimensional solutions but all I got is something slightly different , like itertools.product that iterates with a fixed number of values, e.g.

itertools.product([0,'n'],repeat=6)

[(0, 0, 0, 0, 0, 0),....('n', 'n', 'n', 'n', 'n', 'n')]

any hint would be gladly appreciated



from Recent Questions - Stack Overflow https://ift.tt/2KBqXvs
https://ift.tt/eA8V8J

No comments:

Post a Comment