打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
成功解决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)

成功解决!

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
numpy库入门
利用Python进行数据分析:【NumPy】
Python 数据分析基础包:Numpy
技术图文:Numpy 一维数组 VS. Pandas Series
基于类型化 memoryview 让 Numpy 数组和 C 数组共享内存
数据科学必备Python使用Pandas方法汇总
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服