您当前的位置: 首页 >  ar
  • 0浏览

    0关注

    2393博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

成功解决TypeError: Object of type 'ndarray' is not JSON serializable

一个处女座的程序猿 发布时间:2018-08-19 22:48:06 ,浏览量:0

  解决问题

TypeError: Object of type 'ndarray' is not JSON serializable

解决方法
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,)): # add this line
        return obj.tolist() # add this line
    return json.JSONEncoder.default(self, obj)

成功解决!

 

 

关注
打赏
1664196048
查看更多评论
立即登录/注册

微信扫码登录

0.0440s