def moving_average(array, N=3):
    """compute the moving average for a list/array. N is the number
    of elements averaged over, it always uses the quiered element as the central
    point and hence must be an odd number"""
    if not isinstance(N, int) or N % 2 == 0:
        raise Exception('N must be an odd integer')
    idx = round(N / 2) - 1
    length = len(array)
    out = [0] * length
    for i in range(len(array)):
        if i < idx:
            a = 0
            b = i + idx + 1
        elif length - i < idx:
            a = i - idx
            b = len(array) - 1
        else:
            a = i - idx
            b = i + idx + 1
        out[i] = sum(array[a:b]) / len(array[a:b])
    return out
