<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def calc_mean_hr(rr, fs=None, min_rr=None, max_rr=None, rr_units='samples'):
 """ Compute mean heart rate in beats per minute, from a set of rr intervals. Returns 0 if rr is empty. Parameters rr : numpy array Array of rr intervals. fs : int, or float The corresponding signal's sampling frequency. Required if 'input_time_units' == 'samples'. min_rr : float, optional The minimum allowed rr interval. Values below this are excluded when calculating the heart rate. Units are in `rr_units`. max_rr : float, optional The maximum allowed rr interval. Values above this are excluded when calculating the heart rate. Units are in `rr_units`. rr_units : str, optional The time units of the input rr intervals. Must be one of: 'samples', 'seconds'. Returns ------- mean_hr : float The mean heart rate in beats per minute """

    if not len(rr):
        return 0

    if min_rr is not None:
        rr = rr[rr > min_rr]

    if max_rr is not None:
        rr = rr[rr < max_rr]

    mean_rr = np.mean(rr)

    mean_hr = 60 / mean_rr

    # Convert to bpm
    if rr_units == 'samples':
        mean_hr = mean_hr * fs

    return mean_hr