vals = np.convolve(flat_array, np.ones(n), mode='valid')
out = np.pad(vals, (n - 1, 0), 'constant', constant_values=np.nan)
Python/numpy: Most efficient way to sum n elements of an array, so that each output element is the sum of the previous n input elements?