summaryrefslogtreecommitdiff
path: root/lib/utils.py
diff options
context:
space:
mode:
authorDaniel Friesel <daniel.friesel@uos.de>2020-10-30 11:15:45 +0100
committerDaniel Friesel <daniel.friesel@uos.de>2020-10-30 11:15:45 +0100
commitdf04f15d9132ec6b2781edfccc5ad8d33dd3cdd9 (patch)
tree2fa0093fc60bac124cf83ba4d01acf6e2b5706b1 /lib/utils.py
parentc2858f6c1070d7baa87d2f433746adec5042531e (diff)
Add DFATOOL_EXPORT_LASYNC variable for ET+LA / ET+Timer sync eval
Diffstat (limited to 'lib/utils.py')
-rw-r--r--lib/utils.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/utils.py b/lib/utils.py
index d28ecda..adcb534 100644
--- a/lib/utils.py
+++ b/lib/utils.py
@@ -1,3 +1,4 @@
+import json
import numpy as np
import re
import logging
@@ -6,6 +7,18 @@ arg_support_enabled = True
logger = logging.getLogger(__name__)
+class NpEncoder(json.JSONEncoder):
+ def default(self, obj):
+ if isinstance(obj, np.integer):
+ return int(obj)
+ elif isinstance(obj, np.floating):
+ return float(obj)
+ elif isinstance(obj, np.ndarray):
+ return obj.tolist()
+ else:
+ return super(NpEncoder, self).default(obj)
+
+
def running_mean(x: np.ndarray, N: int) -> np.ndarray:
"""
Compute `N` elements wide running average over `x`.