import itertools


def aggr_events(events_raw):
    """Aggregates event vector to the list of compact event vectors.
    Parameters:
        events_raw  --  vector of raw events
    Returns:
        events_aggr --  list of compact event vectors ([onset, offset, event])
    """

    events_aggr = []
    s = 0
    for bit, group in itertools.groupby(events_raw):
        event_length = len(list(group))
        e = s+event_length
        events_aggr.append([s, e, bit])
        s = e
    return events_aggr