def contiguous_regions(mask):
 mask = np.asarray(mask, dtype=bool)
 if (not mask.size):
  return []
 (idx,) = np.nonzero((mask[:(-1)] != mask[1:]))
 idx += 1
 idx = idx.tolist()
 if mask[0]:
  idx = ([0] + idx)
 if mask[(-1)]:
  idx.append(len(mask))
 return list(zip(idx[::2], idx[1::2]))

def contiguous_regions ( mask ) : mask = np . asarray ( mask , dtype = bool ) if ( not mask . size ) : return [ ] ( idx , ) = np . nonzero ( ( mask [ : ( - 1 ) ] != mask [ 1 : ] ) ) idx += 1 idx = idx . tolist ( ) if mask [ 0 ] : idx = ( [ 0 ] + idx ) if mask [ ( - 1 ) ] : idx . append ( len ( mask ) ) return list ( zip ( idx [ : : 2 ] , idx [ 1 : : 2 ] ) )
return a list of such that mask[ind0:ind1] .