def contiguous_regions(condition):
    """Finds contiguous True regions of the boolean array "condition". Returns
    a 2D array where the first column is the start index of the region and the
    second column is the end index."""
d = np.diff(condition)
idx, = d.nonzero()
idx += 1
if condition[0]:
    idx = np.r_[0, idx]
if condition[-1]:
    idx = np.r_[idx, condition.size]
idx.shape = -1, 2
return idx
main()
Find large number of consecutive values fulfilling condition in a numpy array