So lets say we have a Matrix M
M=np.array([[1,2,3],
[1,2,3],
[1,2,3],
[1,2,3]
[1,2,3],
[1,2,3]])
with the same number of rows as the length of a np.array mask:
mask = np.array([False,True,False,True,False,True])
And there is additional Parameter called threshold=2
I want to subset M with mask only until 2 True values, for all of the remaining I would set false. That means that M[mask] should return me second and fourth row only not the last one. Is there an efficient way to do this with numpy avoiding for loops?