Circularly moving sum
MATL, 11 10 9 7 bytes
3 Bytes saved thanks to @Luis!
:gyn&Z+
The first input is the size of the window and the second input is the array
Try it at MATL Online
Explanation
% Implicitly grab the first input (n)
% STACK: { 3 }
: % Create the array [1...n]
% STACK: { [1, 2, 3] }
g % Convert it to a logical array, yielding an array of 1's of length n
% STACK: { [1, 1, 1] }
y % Implicitly grab the second input and duplicate it
% STACK: { [2, 4, -3, 0, -4], [1, 1, 1], [2, 4, -3, 0, -4]}
n % Determine the length of the array
% STACK: { [2, 4, -3, 0, -4], [1, 1, 1], 5}
&Z+ % Perform circular convolution
% STACK: { [-2, 2, 3, 1, -7] }
% Implicitly display the result
Mathematica, 29 bytes
RotateLeft[#,1-n]~Sum~{n,#2}&
Or the same length:
ListConvolve[1~Table~#2,#,1]&
CJam (16 bytes)
{_2$*ew1fb\,~)>}
Online test suite. This is an anonymous block (function) which takes the array and the length on the stack and leaves an array on the stack.
Dissection
{ e# Declare a block
_2$* e# Repeat the array n times: this guarantees having enough windows even
e# if x is only a single element
ew e# Take each window of n elements
1fb e# Sum each of the windows
\,~) e# Compute -n
> e# Take the last n elements of the array of sums
}