def _contiguous_regions(condition):
 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

def _contiguous_regions ( condition ) : 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
finds contiguous true regions of the boolean array "condition" .