def calc_num_beats(rpeak_locs, metrics):
    """Calculates the number of beats in an ECG

    This function takes an array of the ECG R-peaks. The number of R-peaks
    is equivalent to the number of beats in the ECG.

    Args:
        rpeak_locs (1D numpy array): index locations of R-peaks in an ECG.
        metrics (dict): dictionary containing the metrics which will be
            returned at the end of the program.

    Returns:
        dict: dictionary with added field for the number of beats
    """

    # Add the number of beats
    num_beats = len(rpeak_locs)
    metrics['num_beats'] = int(num_beats)

    return metrics