def staticMovingAverage2(x, N=<NUM_LIT:3>, mode='<STR_LIT>'):
assert N > <NUM_LIT:1><EOL>x2 = np.empty(shape=x.shape[<NUM_LIT:0>] + N, dtype=x.dtype)<EOL>start = N - <NUM_LIT:2><EOL>if N == <NUM_LIT:2>:<EOL><INDENT>start = <NUM_LIT:1><EOL><DEDENT>end = N - start<EOL>x2[start:-end] = x<EOL>if mode == '<STR_LIT>':<EOL><INDENT>x2[:start] = x[<NUM_LIT:0>] + x[<NUM_LIT:0>] - x[start - <NUM_LIT:1>::-<NUM_LIT:1>]<EOL>x2[-end:] = x[-<NUM_LIT:1>] + x[-<NUM_LIT:1>] - x[-<NUM_LIT:2>:-end - <NUM_LIT:2>:-<NUM_LIT:1>]<EOL><DEDENT>elif mode == '<STR_LIT>':<EOL><INDENT>x2[:start] = x[<NUM_LIT:0>]<EOL>x2[-end:] = x[-<NUM_LIT:1>]<EOL><DEDENT>else:<EOL><INDENT>raise NotImplementedError("<STR_LIT>" % mode)<EOL><DEDENT>a1 = np.cumsum(x2)<EOL>a1 = (a1[N:] - a1[:-N]) / N<EOL>a2 = np.cumsum(x2[::-<NUM_LIT:1>])<EOL>a2 = (a2[N:] - a2[:-N]) / N<EOL>return <NUM_LIT:0.5> * (a1 + a2[::-<NUM_LIT:1>])<EOL>cumsum = np.cumsum(x2)<EOL>return (cumsum[N:] - cumsum[:-N]) / N<EOL>
moving average filter for 1d arrays
supported modes for boundary handling: 'reflect' , 'constant'