def flags2segs(flags, window):
    '''
    ARGUMENTS:
     - flags:      a sequence of class flags (per time window)
     - window:     window duration (in seconds)

    RETURNS:
     - segs:       a sequence of segment's limits: segs[i,0] is start and
                   segs[i,1] are start and end point of segment i
     - classes:    a sequence of class flags: class[i] is the class ID of
                   the i-th segment
    '''

    preFlag = 0
    cur_flag = 0
    n_segs = 0

    cur_val = flags[cur_flag]
    segsList = []
    classes = []
    while (cur_flag < len(flags) - 1):
        stop = 0
        preFlag = cur_flag
        preVal = cur_val
        while (stop == 0):
            cur_flag = cur_flag + 1
            tempVal = flags[cur_flag]
            if ((tempVal != cur_val) | (cur_flag == len(flags) - 1)):  # stop
                n_segs = n_segs + 1
                stop = 1
                cur_seg = cur_val
                cur_val = flags[cur_flag]
                segsList.append((cur_flag * window))
                classes.append(preVal)
    segs = numpy.zeros((len(segsList), 2))

    for i in range(len(segsList)):
        if i > 0:
            segs[i, 0] = segsList[i-1]
        segs[i, 1] = segsList[i]
    return (segs, classes)
def flags2segs ( flags , window ) : preFlag = 0 cur_flag = 0 n_segs = 0 cur_val = flags [ cur_flag ] segsList = [ ] classes = [ ] while ( cur_flag < len ( flags ) - 1 ) : stop = 0 preFlag = cur_flag preVal = cur_val while ( stop == 0 ) : cur_flag = cur_flag + 1 tempVal = flags [ cur_flag ] if ( ( tempVal != cur_val ) | ( cur_flag == len ( flags ) - 1 ) ) : n_segs = n_segs + 1 stop = 1 cur_seg = cur_val cur_val = flags [ cur_flag ] segsList . append ( ( cur_flag * window ) ) classes . append ( preVal ) segs = numpy . zeros ( ( len ( segsList ) , 2 ) ) for i in range ( len ( segsList ) ) : if i > 0 : segs [ i , 0 ] = segsList [ i - 1 ] segs [ i , 1 ] = segsList [ i ] return ( segs , classes )
ARGUMENTS:
     - flags:      a sequence of class flags (per time window)
     - window:     window duration (in seconds)

    RETURNS:
     - segs:       a sequence of segment's limits: segs[i,0] is start and
                   segs[i,1] are start and end point of segment i
     - classes:    a sequence of class flags: class[i] is the class ID of
                   the i-th segment