我想要将一个词典写入json文件中。我可以使用以下代码来实现:
with open("my_file.json","w+") as f:
json.dumps(my_dict,f)
但是写完后,我发现一个空的 JSON 文件。my_dict
的每个元素都是一个单词作为键和其 50 长度的单词嵌入向量作为值,例如单词 girl
和其向量:
'girl': [-0.1311900019645691, -0.1871200054883957, 0.43307000398635864, -0.41328999400138855, -0.29401999711990356, -0.004130200017243624, 0.26743999123573303, -0.07822400331497192, 0.5190600156784058, 0.7133600115776062, -0.3792000114917755, -0.880620002746582, 0.9063299894332886, -0.3437800109386444, -0.06771499663591385, -0.2867799997329712, -0.2138500064611435, 0.5637699961662292, 0.23059000074863434, 0.36699000000953674, 0.3780199885368347, -0.11691000312566757, 0.2890999913215637, -0.20220999419689178, -0.5123500227928162, 0.894569993019104, 0.17660999298095703, -0.1632000058889389, 0.4038200080394745, 0.1188800036907196, -1.2901999950408936, 0.02515999972820282, -0.21669000387191772, 0.9924299716949463, 0.24647000432014465, -0.12221000343561172, -0.05487800016999245, 0.2543500065803528, -0.5199699997901917, 0.28192999958992004, 0.45430999994277954, -0.5873399972915649, 0.26017001271247864, 0.42120999097824097, -0.4826599955558777, -0.1054999977350235, -0.29346001148223877, 0.38749998807907104, -0.9690999984741211, -0.44870999455451965]
我该如何解决这个问题?谢谢。