I have a numpy array like this:
[[1, 2], [1, 3], [2, 1], [2, 2], [2, 3], ...]
I would like to get the combinations of all "sub" arrays (i.e [X, Y]) three by three:
[[1, 1] [1, 1] [1, 1],
[1, 1] [1, 1] [1, 2],
[1, 1] [1, 1] [1, 3],
...
[5, 5] [5, 5], [5, 4],
[5, 5] [5, 5], [5, 5]]
Then, I need to apply conditions on each combinations:
X1, X2, X3 > 0
X1+Y1 <= X2
X2+Y2 <= X3
[X1, Y1] =! [X2, Y2]
[X2, Y2] =! [X3, Y3]
...
I absolutely need to avoid for loops because of the high number of combinations.
Any idea how to get this done in an effective time of execution?
My current code with for loops and if statements:
The mylist object is like [[1, 1], [1, 2], [2, 1], ...] (i.e list of lists like [X, Y]).
Combination = [] for left in mylist:
if left[0] > 0:
for center in mylist:
if (center[0] > 0
and center[0] >= left[0] + left[1]
and center[1] / left[1] < 2
and center[0] / left[0] < 2
and left[1] / center[1] < 2
and left[0] / center[1] < 2
and str(left[0]) + "y" + str(left[1]) + "y" != str(center[0]) + "y" + str(center[1]) + "y"
):
for right in mylist:
if (right[0] > 0
and right[0] >= center[0] + center[1]
and right[1] / center[1] < 2
and right[0] / center[0] < 2
and center[1] / right[1] < 2
and center[0] / right[0] < 2
and str(right[0]) + "y" + str(right[1]) + "y" != str(center[0]) + "y" + str(center[1]) + "y"
):
Combination.append([[left[0], left[1]], [center[0], center[1]], [right[0], right[1]])