python - 将 numpy 数组保存到 txt

标签 python arrays numpy

我必须使用每个具有不同列数的数组(q,I),并且我想将它们保存在保留列顺序的txt文件中,这意味着在txt文件中数组应该是这样的:

q, I0, I1, I2, ...

我的数组的形状是:

q.shape = (300, )
I.shape = (300, 12)

我尝试过这个:

save_arrays = np.array(zip(q, I))
np.savetxt('dummy.txt', save_arrays, delimiter='\t', newline='\r\n',
        fmt='%.5f', header='q [A-1]/I [a.u.]')

save_arrays 的形状为:

save_arrays.shape = (300, 2)

它有两列,而不是 13 列。这些列是单数组 q 和多列数组 I。

无论如何,我也收到了这个 TypeError:

TypeError: Mismatch between array dtype ('object') and format specifier ('%.5f %.5f') 

感谢任何帮助。

最佳答案

尝试 save_arrays = np.hstack((q[:,np.newaxis],I))

关于python - 将 numpy 数组保存到 txt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39467517/

相关文章:

python - 如何矢量化使用其自身输出的滞后值的函数?

python - Scrapy Splash 截图?

python - "no such file or directory python"激活Python环境

python - 机器人测试接收到的 unicode 与从 python 关键字发送的不同

arrays - 在MATLAB中: How should nested fields of a struct be converted to a cell array?

arrays - 可以查询 postgresql 的列数组维度吗? (测试列是否为 int[][]?)

Python Pandas 找到非零索引

python - numpy 中的多维数组乘法

python - 如何在Google Colab中播放mp4视频

javascript - 在 JavaScript 中检查数组是否包含具有特定属性值的对象?