Skip to content

Commit d05d456

Browse files
author
arch
committed
improve avg function
1 parent 3e20ea8 commit d05d456

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

funscript_editor/algorithms/signal.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,14 @@ def moving_average(x: list, w: int) -> list:
5858
if len(x) == 0:
5959
return []
6060

61-
if len(x) <= w+1:
61+
if len(x) <= 2*(w+1):
6262
return[np.mean(x) for _ in range(len(x))]
6363

6464
if w == 1:
6565
return x
6666

67-
return np.convolve(x, np.ones(int(w*2)) / (w*2), 'same')
67+
avg = np.convolve(x, np.ones(int(w*2)) / (w*2), 'valid')
68+
return [sum(x[:i*2]) / (i*2) for i in range(1, w+1)]+list(avg)+[sum(x[-i*2:]) / (i*2) for i in range(w, 1, -1)]
6869

6970

7071
@staticmethod

0 commit comments

Comments
 (0)