For some statistical whatnot I decided to calculate the running mean with the rep() function in r. However, I'd like to transfer this to python because my r library is limited. I did find that np.repeat is supposed to be similar to rep(), however, I don't fully understand how to achieve the same in python as when I run this in r:
x <- 1:300
print(filter(x,rep(1/30,30)))
Thanks for your help!
You already named the right commands.
x = range(1,301)
np.convolve(x, np.repeat(1/30, 30))[2:-2]
The last brackets cut off the first two and the last two elements, because convolve goes beyond the list, which does not seem reasonable to me.
This way, the first entry is the average of 1-30 and the last entry is the average 271-300.