import numpy as np
import codecs, json
a = np.arange(10).reshape(2,5) # a 2 by 5 array
b = a.tolist() # nested lists with same data, indices
file_path = "/path.json" ## your path variable
json.dump(b, codecs.open(file_path, 'w', encoding='utf-8'), separators=(',', ':'), sort_keys=True, indent=4) ### this saves the array in .json format
将numpy.ndarray或任何嵌套的列表组合存储为JSON。
将输出:
要从JSON还原,请执行以下操作:
将输出:
我经常“jsonify”np.数组。首先尝试对数组使用“.tolist()”方法,如下所示:
为了“取消对数组的合理化”,请使用:
您可以使用Pandas:
相关问题 更多 >
编程相关推荐