def find_range(index, window, max):
    """ find the left and right endpoints of a window in an array

    :param index: index window is to be centered at
    :param window: the length of the window
    :param max: the size of the array
    :return: left and right endpoints of the window
    """
    half_window = int(window / 2)

    return (
        (index - half_window, index + half_window)  # in range
        if max - half_window >= index >= half_window else
        (max - window, max)  # too far on right
        if max - half_window < index else
        (0, window)  # to far on left
    )