TypeError: Mismatch between array dtype (#39;object#39;) and format specifier (#39;%.18e#39;)(TypeError: 数组 dtype (object) 和格式说明符 (%.18e) 不匹配)
问题描述
我有以下数组:
X
的打印结果如下:
当我尝试将数据另存为 txt 时:
When I try to save the data as txt:
我得到以下信息:
这是为什么呢?我该如何解决这个问题?
Why is that? How can I solve the issue?
谢谢.
推荐答案
如果没有一些示例数据,复制这个有点困难,但这是我想出的.
It's a little difficult to duplicate this without some example data, but here is what I came up with.
正如@Artier 所指出的,在 将对象数组写入 .txt 文件 指出您可以使用 fmt='%s'
将数组保存为字符串.使用这种格式似乎可以解决我的问题(同样,如果没有数据样本,我无法完全重现您的问题).
As pointed out by @Artier there is a little snippet at the end of the accepted answer in Write object array to .txt file
that points out you can just save the array as a string with fmt='%s'
. Using this format seems to solve the problem for me (again I can't recreate your issue exactly without a sample of data).
我会指出,如果您要保存不同的数组并希望在一个位置保存它们 savez
非常有用.
I would point out that if you are looking to save disparate arrays and want a single location to keep them savez
is very useful.
这篇关于TypeError: 数组 dtype ('object') 和格式说明符 ('%.18e') 不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!