I have a n-dimension array as shown below:
np.array([[0,3],[0,3],[0,10]])
In this array, the elements denote the low and high values. Ex: [0,3]
refers to [0,1,2,3]
I need to generate a combination of all values using the ranges given as above.
For example, I want [0,0,0], [0,0,1] ... [0,1,0] ... [3,3,10]
I have tried the following to get what I want:
ds = np.array([[0,3],[0,3],[0,10]])
nItems = int(reduce(lambda a,b: a * (b[1] - b[0] + 1), ds, 1))
myCombinations = np.zeros((nItems,))
nArrays = []
for x in range(ds.shape[0]):
low = ds[x][0]
high= ds[x][1]
nitm = high - low + 1
ar = [x+low for x in range(nitm) ]
nArrays.append(ar)
myCombinations = cartesian(nArrays)
The cartesian function was taken from Using numpy to build an array of all combinations of two arrays
I need to do this few million times.
My question: is there any better / efficient way to do this?