def flip_heatmap(heatmap, joint_pairs, shift=False):
    """Flip pose heatmap according to joint pairs.

    Parameters
    ----------
    heatmap : numpy.ndarray
        Heatmap of joints.
    joint_pairs : list
        List of joint pairs
    shift : bool
        Whether to shift the output

    Returns
    -------
    numpy.ndarray
        Flipped heatmap

    """
    assert heatmap.ndim == 3, 'heatmap should have shape (num_joints, height, width)'
    out = heatmap[:, :, ::-1]
    for pair in joint_pairs:
        tmp = out[(pair[0]), :, :].copy()
        out[(pair[0]), :, :] = out[(pair[1]), :, :]
        out[(pair[1]), :, :] = tmp
    if shift:
        out[:, :, 1:] = out[:, :, 0:-1]
    return out
