Created
February 6, 2018 21:47
-
-
Save vvanirudh/bc4557f72d3b2877c77b8cac77950a6a to your computer and use it in GitHub Desktop.
Computing sliding mean to smooth curves
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def sliding_mean(data_array, window=5): | |
data_array = np.array(data_array) | |
new_list = [] | |
for i in range(len(data_array)): | |
indices = range(max(i - window + 1, 0), | |
min(i + window + 1, len(data_array))) | |
avg = 0 | |
for j in indices: | |
avg += data_array[j] | |
avg /= float(len(indices)) | |
new_list.append(avg) | |
return np.array(new_list) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment