File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"
77
88[project ]
99name = " spotPython"
10- version = " 0.14.2 "
10+ version = " 0.14.3 "
1111authors = [
1212 { name =" T. Bartz-Beielstein" , email =" tbb@bartzundbartz.de" }
1313]
Original file line number Diff line number Diff line change 1+ import json
2+ import numpy as np
3+
4+
5+ class NumpyEncoder (json .JSONEncoder ):
6+ """
7+ JSONEncoder subclass that knows how to encode numpy arrays.
8+
9+ Note:
10+ Taken from:
11+ https://stackoverflow.com/questions/26646362/numpy-array-is-not-json-serializable
12+
13+ """
14+
15+ def default (self , obj ):
16+ if isinstance (obj , np .integer ):
17+ return int (obj )
18+ elif isinstance (obj , np .floating ):
19+ return float (obj )
20+ elif isinstance (obj , np .bool_ ):
21+ return int (obj )
22+ elif isinstance (obj , np .ndarray ):
23+ return obj .tolist ()
24+ elif isinstance (obj , np .float64 ):
25+ if np .isnan (obj ):
26+ return "NaN"
27+ elif np .isinf (obj ):
28+ return "Inf"
29+ else :
30+ return float (obj )
31+ return json .JSONEncoder .default (self , obj )
You can’t perform that action at this time.
0 commit comments