Object of type 'ndarray' is not JSON serializable

Object of type 'ndarray' is not JSON serializable

import numpy as np
import json


arr=np.asarray([345,45])
result={'name':'test','num':ar}


json.dump(result)

解决方法:

result={'name':'text','num':ar.tolist()}

json不认numpy的array

原文地址:https://www.cnblogs.com/gmhappy/p/11863990.html