import numpy as np
import json
arr = np.asarray([345, 45])
result = {'name': 'test', 'num': arr}
json.dump(result)
报错:
TypeError: Object of type ndarray is not JSON serializable
解决办法:
result={'name':'text','num':arr.tolist()}
import numpy as np
import json
arr = np.asarray([345, 45])
result = {'name': 'test', 'num': arr}
json.dump(result)
报错:
TypeError: Object of type ndarray is not JSON serializable
解决办法:
result={'name':'text','num':arr.tolist()}