當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
成功解决TypeError: Object of type 'ndarray' is not JSON serializable
生活随笔
收集整理的這篇文章主要介紹了
成功解决TypeError: Object of type 'ndarray' is not JSON serializable
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?
解決問題
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 linereturn obj.tolist() # add this linereturn json.JSONEncoder.default(self, obj)成功解決!
?
?
總結
以上是生活随笔為你收集整理的成功解决TypeError: Object of type 'ndarray' is not JSON serializable的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 成功解决AttributeError:
- 下一篇: ML之Clustering之K-mean