def staticMovingAverage2(x, N=3, mode='reflect'):
    """
    moving average filter for 1d arrays
    supported modes for boundary handling: 'reflect' , 'constant'

    """
    assert N > 1
    x2 = np.empty(shape=x.shape[0] + N, dtype=x.dtype)

    start = N - 2
    if N == 2:
        start = 1
    end = N - start

    x2[start:-end] = x
    # boundaries
    if mode == 'reflect':
        x2[:start] = x[0] + x[0] - x[start - 1::-1]
        x2[-end:] = x[-1] + x[-1] - x[-2:-end - 2:-1]
    elif mode == 'nearest':
        x2[:start] = x[0]
        x2[-end:] = x[-1]
    else:
        raise NotImplementedError("mode='%s' not supported" % mode)
    a1 = np.cumsum(x2)
    a1 = (a1[N:] - a1[:-N]) / N

    a2 = np.cumsum(x2[::-1])
    a2 = (a2[N:] - a2[:-N]) / N

    return 0.5 * (a1 + a2[::-1])
    # TODO: unreachable code
    cumsum = np.cumsum(x2)
    return (cumsum[N:] - cumsum[:-N]) / N
moving average filter for 1d arrays
    supported modes for boundary handling: 'reflect' , 'constant'