Thanks for the fast and intuitive answer! One question remains: I was kind of surprised by your way to find idx. Is that really the most efficient way of finding the index of the largest False element of is_le? numel() is probably constant in the size of is_le, but sum() should be linear?