I have a Numpy array of shape N, 3, 2. I will call a combination each element of shape 3, 2 (So there are N combinations). I want to apply "tests" on values inside each combination. If a condition is not satisfied, I would like to delete the combination where the condition is not satisfied.
Let's say I have this array:
array[[[1, 1],
[2, 2],
[3, 3]],
[[2, 1],
[2, 2],
[2, 3]],
[[3, 1],
[3, 2],
[3, 3]]]
I want to check that all values on the left are > 1. Currently I do: myArr = myArr[myArr[:, :, 0] > 1]
Running this, it only delete the [1, 1] element, not the whole combination (i.e. [[1, 1], [2, 2], [3, 3]]).
How can I achieve this? Without for loops if possible ? (I have a high number of combinations)
Currently, my code is like:
#X is the left value and Y the right value, each combination having 3 elements like [X, Y] I used Xt or Yt with t=1 to 3 in my comments later.
Limit = 2
b = np.array([[[1, 1], [2, 2], [3, 3]],
[[2, 1], [2, 2], [2, 3]],
[[3, 1], [3, 2], [3, 3]],
[[4, 3], [4, 2], [3, 1]]])
#All X > 0
b = b[b[:, :, 0] > 0].reshape(-1, 3, 2)
#X1 + Y1 <= X2
b = b[b[:, 0, 0] + b[:, 0, 1] <= b[:, 1, 0]].reshape(-1, 3, 2)
#X2 + Y2 <= X3
b = b[b[:, 1, 0] + b[:, 1, 1] <= b[:, 2, 0]].reshape(-1, 3, 2)
#X2 / X1
b = b[b[:, 1, 0] / b[:, 0, 0] <= Limit].reshape(-1, 3, 2)
#Y2 / Y1
b = b[b[:, 1, 1] / b[:, 0, 1] <= Limit].reshape(-1, 3, 2)
#X3 / X2
b = b[b[:, 2, 0] / b[:, 1, 0] <= Limit].reshape(-1, 3, 2)
#Y3 / Y2
b = b[b[:, 2, 1] / b[:, 1, 1] <= Limit].reshape(-1, 3, 2)
#X1 / X2
b = b[b[:, 0, 0] / b[:, 1, 0] <= Limit].reshape(-1, 3, 2)
#Y1 / Y2
b = b[b[:, 0, 1] / b[:, 1, 1] <= Limit].reshape(-1, 3, 2)
#X2 / X3
b = b[b[:, 1, 0] / b[:, 2, 0] <= Limit].reshape(-1, 3, 2)
#Y2 / Y3
b = b[b[:, 1, 1] / b[:, 2, 1] <= Limit].reshape(-1, 3, 2)
#Comb 1 != Comb 2
b = b[(b[:, 0, 0] != b[:, 1, 0]) & (b[:, 0, 1] != b[:, 1, 1])].reshape(-1, 3, 2)
#Comb 2 != Comb 3
b = b[(b[:, 1, 0] != b[:, 2, 0]) & (b[:, 1, 1] != b[:, 2, 1])].reshape(-1, 3, 2)