我定期“ jsonify” np.arrays。尝试首先在数组上使用“ .tolist()”方法,如下所示:
import numpy as npimport precs, json a = np.arange(10).reshape(2,5) # a 2 by 5 arrayb = a.tolist() # nested lists with same data, indicesfile_path = "/path.json" ## your path variablejson.dump(b, precs.open(file_path, 'w', encoding='utf-8'), separators=(',', ':'), sort_keys=True, indent=4) ### this saves the array in .json format为了“ unjsonify”数组使用:
obj_text = precs.open(file_path, 'r', encoding='utf-8').read()b_new = json.loads(obj_text)a_new = np.array(b_new)



