<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def select_events(dat, detected, method, value):
 """Select start sample and end sample of the events. Parameters dat : ndarray (dtype='float') vector with the data after selection-transformation detected : ndarray (dtype='int') N x 3 matrix with start, peak, end samples method : str 'above_thresh', 'below_thresh' value : float for 'threshold', it's the value of threshold for the spindle selection. Returns ------- ndarray (dtype='int') N x 3 matrix with start, peak, end samples """

    if method == 'above_thresh':
        above_sel = dat >= value
        detected = _select_period(detected, above_sel)
    elif method == 'below_thresh':
        below_sel = dat <= value
        detected = _select_period(detected, below_sel)

    return detected