I'm doing smoothing of some sequential integer data that I have in a list. My smoothing method is to replace each number with the mean of that number and its neighbors. I'm currently doing that with this code:
from statistics import mean
smoothednums = [mean(nums[:2])] + [mean(nums[i-1:i+2]) for i in range(1,len(nums))]
This has significantly increased the runtime of my script. Is there a better way to do this operation?