Python:TypeError: array([ 1.]) is not JSON serializable

不羁的心 提交于 2019-12-04 16:33:28

I have solved my problem by changing file "mpld3/_display.py".

Please change below part:

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)

Please refer https://github.com/javadba/mpld3/commit/57ed37dbc4749259b1b46cba8bf28de802972adb for more detail.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!