From df04f15d9132ec6b2781edfccc5ad8d33dd3cdd9 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Fri, 30 Oct 2020 11:15:45 +0100 Subject: Add DFATOOL_EXPORT_LASYNC variable for ET+LA / ET+Timer sync eval --- lib/utils.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'lib/utils.py') 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`. -- cgit v1.2.3