简体   繁体   English

将numpy数组保存到txt

[英]save numpy arrays to txt

I have to arrays (q, I) with different number of columns each and I want to save them in a txt file preserving the order of the columns, meaning in the txt file the arrays should be like: 我必须分别具有不同列数的数组(q,I),并且我想将它们保存在txt文件中,以保留列的顺序,这意味着在txt文件中,数组应类似于:

q, I0, I1, I2, ...

The shape of my arrays are: 我的数组的形状是:

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

I tried this: 我尝试了这个:

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.]')

The shape of save_arrays is: save_arrays的形状为:

save_arrays.shape = (300, 2)

It has two columns instead of 13. Those columns are the single array q and the multi-column array I. 它具有两列而不是13列。这些列是单数组q和多列数组I。

Anyway, I'm getting this TypeError as well: 无论如何,我也收到此TypeError:

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

Any help is appreciated. 任何帮助表示赞赏。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM