1. <small id='HE1S5'></small><noframes id='HE1S5'>

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

        从 0-d numpy 数组中恢复字典

        时间:2023-10-19

            <legend id='9rYUr'><style id='9rYUr'><dir id='9rYUr'><q id='9rYUr'></q></dir></style></legend>
              <tbody id='9rYUr'></tbody>
                <bdo id='9rYUr'></bdo><ul id='9rYUr'></ul>

              • <small id='9rYUr'></small><noframes id='9rYUr'>

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

                  本文介绍了从 0-d numpy 数组中恢复字典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  发生的事情是我(错误地)使用命令 numpy.save() 保存了一个字典(没有显示错误消息),现在我需要恢复字典中的数据.当我用 numpy.load() 加载它时,它的类型为 (numpy.ndarray) 并且是 0-d,所以它不再是字典,我可以t 访问其中的数据,0-d 数组是不可索引的,所以做类似

                  What happened is that I (by mistake) saved a dictionary with the command numpy.save() (no error messages shown) and now I need to recover the data in the dictionary. When I load it with numpy.load() it has type (numpy.ndarray) and is 0-d, so it is not a dictionary any more and I can't access the data in it, 0-d arrays are not index-able so doing something like

                  mydict = numpy.load('mydict')
                  mydict[0]['some_key'] 
                  

                  不起作用.我也试过了

                  recdict = dict(mydict)
                  

                  但这也没有用.

                  为什么当我用 numpy.save() 保存字典时 numpy 没有警告我?

                  Why numpy didn't warn me when I saved the dictionary with numpy.save()?

                  有没有办法恢复数据?

                  提前致谢!

                  推荐答案

                  使用 mydict.item() 以 Python 标量的形式获取数组元素.

                  Use mydict.item() to obtain the array element as a Python scalar.

                  >>> import numpy as np
                  >>> np.save('/tmp/data.npy',{'a':'Hi Mom!'})
                  >>> x=np.load('/tmp/data.npy')
                  >>> x.item()
                  {'a': 'Hi Mom!'}
                  

                  这篇关于从 0-d numpy 数组中恢复字典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Django:何时自定义保存与使用保存后信号 下一篇:如何用 Python 保存数据?

                  相关文章

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

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

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

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

                2. <legend id='Snc4y'><style id='Snc4y'><dir id='Snc4y'><q id='Snc4y'></q></dir></style></legend>