def contiguous_regions(condition):
<EOL>d = np.diff(condition, n=<NUM_LIT:1>)<EOL>idx, = d.nonzero()<EOL>idx += <NUM_LIT:1><EOL>if condition[<NUM_LIT:0>]:<EOL><INDENT>idx = np.r_[<NUM_LIT:0>, idx]<EOL><DEDENT>if condition[-<NUM_LIT:1>]:<EOL><INDENT>idx = np.r_[idx, condition.size]<EOL><DEDENT>idx.shape = (-<NUM_LIT:1>, <NUM_LIT:2>)<EOL>return idx<EOL>
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.
    http://stackoverflow.com/questions/4494404/find-large-number-of-consecutive-values-fulfilling-condition-in-a-numpy-array