Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
对于一些统计信息,我决定使用 r 中的 rep() 函数计算运行平均值。但是,我想将其转移到 python,因为我的 r 库是有限的。我确实发现 np.repeat 应该类似于 rep(),但是,我不完全理解如何在 python 中实现与在 r 中运行它时相同的效果:
x <- 1:300 print(filter(x,rep(1/30,30)))
谢谢你的帮助!
您已经命名了正确的命令。
x = range(1,301) np.convolve(x, np.repeat(1/30, 30))[2:-2]
最后的括号切断了前两个和最后两个元素,因为 convolve 超出了列表,这对我来说似乎不合理。
这样,第一个条目是 1-30 的平均值,最后一个条目是 271-300 的平均值。