Error: TypeError: array([1.]) is not JSON serializable
Hata: TypeError: array([1.]) is not JSON serializable
Çözüm:
site-packages\mpld3 klasörü içerisindeki “_display.py” dosyası içerisinde yer alan aşağıdaki kodu
class NumpyEncoder(json.JSONEncoder): """ Special json encoder for numpy types """ def default(self, obj): if isinstance(obj, (numpy.int_, numpy.intc, numpy.intp, numpy.int8, numpy.int16, numpy.int32, numpy.int64, numpy.uint8, numpy.uint16,numpy.uint32, numpy.uint64)): return int(obj) elif isinstance(obj, (numpy.float_, numpy.float16, numpy.float32, numpy.float64)): return float(obj) return json.JSONEncoder.default(self, obj)
aşağıda belirtilen kod ile değiştirin.
class NumpyEncoder(json.JSONEncoder): """ Special json encoder for numpy types """ def default(self, obj): if isinstance(obj, (numpy.int_, numpy.intc, numpy.intp, numpy.int8, numpy.int16, numpy.int32, numpy.int64, numpy.uint8, numpy.uint16,numpy.uint32, numpy.uint64)): return int(obj) elif isinstance(obj, (numpy.float_, numpy.float16, numpy.float32, numpy.float64)): return float(obj) elif isinstance(obj,(numpy.ndarray,)): #### This is the fix return obj.tolist() return json.JSONEncoder.default(self, obj)
Sorun ortadan kalkmış olacak.
KAYNAK:
https://github.com/mpld3/mpld3/issues/434