summaryrefslogtreecommitdiff
path: root/lib/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/utils.py')
-rw-r--r--lib/utils.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/utils.py b/lib/utils.py
index a582d6b..26a591e 100644
--- a/lib/utils.py
+++ b/lib/utils.py
@@ -14,6 +14,17 @@ def vprint(verbose, string):
print(string)
+def running_mean(x: np.ndarray, N: int) -> np.ndarray:
+ """
+ Compute `N` elements wide running average over `x`.
+
+ :param x: 1-Dimensional NumPy array
+ :param N: how many items to average
+ """
+ cumsum = np.cumsum(np.insert(x, 0, 0))
+ return (cumsum[N:] - cumsum[:-N]) / N
+
+
def human_readable(value, unit):
for prefix, factor in (('p', 1e-12), ('n', 1e-9), (u'ยต', 1e-6), ('m', 1e-3), ('', 1), ('k', 1e3)):
if value < 1e3 * factor: