【发布时间】:2021-09-05 20:05:16
【问题描述】:
我有一个来自函数 f.example 的二维数组,它返回给我:
array([[ 0.0, 1.0, 2.0, 3.0 ],
[ 5.0, 1.0, 3.0, 3.0 ],
[ 1.0, 1.0, 3.0, 3.0 ]])
事实上,我可以将它写入 csv 文件,但不是我想要的方式。以下是 csv 文件的外观:
0.0 5.0 1.0
1.0 1.0 1.0
2.0 3.0 3.0
3.0 3.0 3.0
但这就是现在的样子:
0.0 1.0 2.0 3.0
5.0 1.0 3.0 3.0
1.0 1.0 3.0 3.0
还有我拥有的代码:
with open('example.csv', 'w') as csvfile:
writer = csv.writer(csvfile)
writer.writerows(f.example)
【问题讨论】:
-
在写出之前转置矩阵
标签: python arrays python-3.x csv