• <legend id='poJu7'><style id='poJu7'><dir id='poJu7'><q id='poJu7'></q></dir></style></legend>

      <i id='poJu7'><tr id='poJu7'><dt id='poJu7'><q id='poJu7'><span id='poJu7'><b id='poJu7'><form id='poJu7'><ins id='poJu7'></ins><ul id='poJu7'></ul><sub id='poJu7'></sub></form><legend id='poJu7'></legend><bdo id='poJu7'><pre id='poJu7'><center id='poJu7'></center></pre></bdo></b><th id='poJu7'></th></span></q></dt></tr></i><div id='poJu7'><tfoot id='poJu7'></tfoot><dl id='poJu7'><fieldset id='poJu7'></fieldset></dl></div>
      <tfoot id='poJu7'></tfoot>

        <small id='poJu7'></small><noframes id='poJu7'>

        • <bdo id='poJu7'></bdo><ul id='poJu7'></ul>

        TypeError: 数组 dtype ('object') 和格式说明符 ('%.18e

        时间:2023-10-19

            <small id='R3cQo'></small><noframes id='R3cQo'>

              <bdo id='R3cQo'></bdo><ul id='R3cQo'></ul>

              <i id='R3cQo'><tr id='R3cQo'><dt id='R3cQo'><q id='R3cQo'><span id='R3cQo'><b id='R3cQo'><form id='R3cQo'><ins id='R3cQo'></ins><ul id='R3cQo'></ul><sub id='R3cQo'></sub></form><legend id='R3cQo'></legend><bdo id='R3cQo'><pre id='R3cQo'><center id='R3cQo'></center></pre></bdo></b><th id='R3cQo'></th></span></q></dt></tr></i><div id='R3cQo'><tfoot id='R3cQo'></tfoot><dl id='R3cQo'><fieldset id='R3cQo'></fieldset></dl></div>
                <tbody id='R3cQo'></tbody>
              <legend id='R3cQo'><style id='R3cQo'><dir id='R3cQo'><q id='R3cQo'></q></dir></style></legend>

              1. <tfoot id='R3cQo'></tfoot>

                • 本文介绍了TypeError: 数组 dtype ('object') 和格式说明符 ('%.18e') 不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有以下数组:

                  X = np.array([image_array_to_vector1,image_array_to_vector2,image_array_to_vector3,image_array_to_vector4])
                  

                  X 的打印结果如下:

                  [array([167, 167, 169, ...,   1,   1,   1], dtype=uint8)
                   array([42, 43, 43, ..., 41, 36, 34], dtype=uint8)
                   array([0, 0, 0, ..., 0, 0, 0], dtype=uint8)
                   array([0, 0, 0, ..., 0, 0, 0], dtype=uint8)]
                  

                  当我尝试将数据另存为 txt 时:

                  When I try to save the data as txt:

                  X_to_text_file = np.savetxt('x.txt',X)
                  

                  我得到以下信息:

                  File "/Library/Python/2.7/site-packages/numpy/lib/npyio.py", line 1258, in savetxt
                      % (str(X.dtype), format))
                  TypeError: Mismatch between array dtype ('object') and format specifier ('%.18e')
                  

                  这是为什么呢?我该如何解决这个问题?

                  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.

                  arr = np.array([np.array([1,2,3]), np.array([1,2,3,4])])
                  arr
                  array([array([1, 2, 3]), array([1, 2, 3, 4])], dtype=object)
                  np.savetxt('x.txt', arr)
                  TypeError: Mismatch between array dtype ('object') and format specifier ('%.18e')
                  

                  正如@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).

                  np.savetxt('x.txt', arr, fmt='%s')
                  

                  我会指出,如果您要保存不同的数组并希望在一个位置保存它们 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') 不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Python文字游戏:如何制作保存功能? 下一篇:如何保存像tsv这样的python输出

                  相关文章

                  <tfoot id='CWJ5n'></tfoot>

                      <legend id='CWJ5n'><style id='CWJ5n'><dir id='CWJ5n'><q id='CWJ5n'></q></dir></style></legend>
                      <i id='CWJ5n'><tr id='CWJ5n'><dt id='CWJ5n'><q id='CWJ5n'><span id='CWJ5n'><b id='CWJ5n'><form id='CWJ5n'><ins id='CWJ5n'></ins><ul id='CWJ5n'></ul><sub id='CWJ5n'></sub></form><legend id='CWJ5n'></legend><bdo id='CWJ5n'><pre id='CWJ5n'><center id='CWJ5n'></center></pre></bdo></b><th id='CWJ5n'></th></span></q></dt></tr></i><div id='CWJ5n'><tfoot id='CWJ5n'></tfoot><dl id='CWJ5n'><fieldset id='CWJ5n'></fieldset></dl></div>
                        <bdo id='CWJ5n'></bdo><ul id='CWJ5n'></ul>
                    1. <small id='CWJ5n'></small><noframes id='CWJ5n'>