小编Map*_*apa的帖子

功能类似于numpy的差异

我想知道是否存在一个函数,它会同时计算移动平均值并将其与np.diff

如果你有一个数组,你可以计算移动窗口的平均值(移动平均值)并计算该平均值和下一个1元素之间的差值.

例:

a = [1, 3, 4, 5, 15, 14, 16, 13]
b = np.diff(a)
#np.diff makes something like this: `[n] - [n-1]`
#I want something like this: `[n] - np.mean([n-m : n])`

#I would like to have a function, where I could vary `m`:

m = 2
d = [2, 1.5, 10.5, 4, 1.5, -2]
Run Code Online (Sandbox Code Playgroud)

我将如何实现它,以便时间计算不会那么长,因为我想将它用于26000个元素和更高的数组m

python math numpy scipy

5
推荐指数
1
解决办法
1695
查看次数

标签 统计

math ×1

numpy ×1

python ×1

scipy ×1