def unmasked_index_ranges(mask, compressed=True):
 mask = mask.reshape(mask.size)
 m = np.concatenate(((1,), mask, (1,)))
 indices = np.arange((len(mask) + 1))
 mdif = (m[1:] - m[:(-1)])
 i0 = np.compress((mdif == (-1)), indices)
 i1 = np.compress((mdif == 1), indices)
 assert (len(i0) == len(i1))
 if (len(i1) == 0):
  return None
 if (not compressed):
  return np.concatenate((i0[:, np.newaxis], i1[:, np.newaxis]), axis=1)
 seglengths = (i1 - i0)
 breakpoints = np.cumsum(seglengths)
 ic0 = np.concatenate(((0,), breakpoints[:(-1)]))
 ic1 = breakpoints
 return np.concatenate((ic0[:, np.newaxis], ic1[:, np.newaxis]), axis=1)

def unmasked_index_ranges ( mask , compressed = True ) : mask = mask . reshape ( mask . size ) m = np . concatenate ( ( ( 1 , ) , mask , ( 1 , ) ) ) indices = np . arange ( ( len ( mask ) + 1 ) ) mdif = ( m [ 1 : ] - m [ : ( - 1 ) ] ) i0 = np . compress ( ( mdif == ( - 1 ) ) , indices ) i1 = np . compress ( ( mdif == 1 ) , indices ) assert ( len ( i0 ) == len ( i1 ) ) if ( len ( i1 ) == 0 ) : return None if ( not compressed ) : return np . concatenate ( ( i0 [ : , np . newaxis ] , i1 [ : , np . newaxis ] ) , axis = 1 ) seglengths = ( i1 - i0 ) breakpoints = np . cumsum ( seglengths ) ic0 = np . concatenate ( ( ( 0 , ) , breakpoints [ : ( - 1 ) ] ) ) ic1 = breakpoints return np . concatenate ( ( ic0 [ : , np . newaxis ] , ic1 [ : , np . newaxis ] ) , axis = 1 )
find index ranges where *mask* is *false* .