您似乎正在尝试在输入数据集上执行步进平均,同时保留初始输入向量的长度。据我所知,没有单一的功能可以做到这一点。
但是,您可以很容易地在 Python 中做到这一点。例如:
def blurryAverage(inputCollection, step=1):
""" Perform a tiling average of an input data set according to its
step length, preserving the length of the initial input vector """
# Preconditions
if (len(inputCollection) % step != 0):
raise ValueError('Input data must be of divisible length')
ret = []
for i in range(len(inputCollection) / step):
tot = 0.0
for j in range(step):
tot += inputCollection[(i*step)+j]
for j in range(step):
ret.append(tot / step) # Implicit float coercion of step
return ret
>>> blurryAverage([1,2,3,4,5,6],3)
[2.0, 2.0, 2.0, 5.0, 5.0, 5.0]
>>> blurryAverage([1,2,3],4)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 3, in blurryAverage
ValueError: Input data must be of divisible length