Skip to content

Instantly share code, notes, and snippets.

@vvanirudh
Created February 6, 2018 21:47
Show Gist options
  • Save vvanirudh/bc4557f72d3b2877c77b8cac77950a6a to your computer and use it in GitHub Desktop.
Save vvanirudh/bc4557f72d3b2877c77b8cac77950a6a to your computer and use it in GitHub Desktop.
Computing sliding mean to smooth curves
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