使用此
with open("./data.dat") as file:
data = [map(float, ln.split()) for ln in file]
可以将数据文件转换为数组。我怎么能做相反的事呢?
具体来说,我想转换像:
[[1,2,3],[4,5,6],[7,8,9]]
到包含以下内容的data.dat文件:
1 2 3
4 5 6
7 8 9
答案 0 :(得分:3)
with open("./data.data", 'w') as file:
for line in data:
file.write(' '.join([str(d) for d in line]) + '\n')