I need to replace a list of numbers, [1,0,3,2,1,4,1,2] for instance, by the moving average with a window of 3. The second element, 0 in this case, should become (1+0+3)/3. The problem I have is that I want to keep the new total the same as the original one, 14 in this case. With the constraint of keeping the same total value, I cannot use a truncated moving average for the first and last elements.
Is there a way around this issue?