0

I have a certain numpy array of integers and I want to make an array of arrays that contains all combinations of numbers below it. As an example, [2,3] would yield

[[1,1],[2,1],[1,2],[2,2],[1,3],[3,3]] 

because that would be all the combinations of arrays with numbers less than or equal to [2,3].

Quang Hoang
  • 146,074
  • 10
  • 56
  • 74

1 Answers1

1

You can use itertools.product:

from itertools import product

a,b = 2,3

list(product(np.arange(a)+1,np.arange(b)+1))

Output:

[(1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (2, 3)]
Quang Hoang
  • 146,074
  • 10
  • 56
  • 74