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

      • <bdo id='KBAcK'></bdo><ul id='KBAcK'></ul>
    1. <legend id='KBAcK'><style id='KBAcK'><dir id='KBAcK'><q id='KBAcK'></q></dir></style></legend>

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

        使用 nditer 进行浅迭代

        shallow iteration with nditer(使用 nditer 进行浅迭代)
      2. <small id='fHT4x'></small><noframes id='fHT4x'>

          <tbody id='fHT4x'></tbody>
          <tfoot id='fHT4x'></tfoot>
          • <bdo id='fHT4x'></bdo><ul id='fHT4x'></ul>

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

                1. 本文介绍了使用 nditer 进行浅迭代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有这样一个数组:

                  >>>y = np.random.randint(0, 255, (2,2,3))
                  >>>array([[[242, 14, 211],
                             [198,  7,   0]],
                  
                            [[235,  60,  81],
                             [164,  64, 236]]])
                  

                  而且我必须遍历每个 triplet 元素(不幸的是,矢量化对我没有帮助......).所以我尝试了:

                  And I have to iterate over each triplet element (unfortunately vectorization won't help me here...). So I tried:

                  for i, j in np.nditer(y):
                  print y[i, j],
                  

                  希望我能得到这样的输出:

                  hoping I'd get such an output:

                  [242, 14, 211], [198, 7, 0], [235, 60, 81], [164, 64, 236],但运气不好!

                  我得到错误:

                  Traceback (most recent call last):
                  
                    File "<ipython-input-21-a336ef837a8a>", line 1, in <module>
                      for i, j in np.nditer(y):    print y[i,j]
                  
                  TypeError: iteration over a 0-d array
                  

                  我很确定我犯了一个非常明显的错误...谁能帮帮我?

                  I'm quite sure I'm making a very obvious error... can anyone please help me?

                  推荐答案

                  看起来你只需要把它拉平.您可以使用 itertools 中的 chain 运算符.

                  It looks like you just need to flatten this down a level. You can use the chain operator from itertools.

                  from itertools import chain    
                  
                  
                  y = np.random.randint(0, 255, (2,2,3)
                  b = chain.from_iterable(y) # where b is a generator
                  

                  list(b) 输出

                  [array([ 51, 119,  84]),
                   array([ 50, 110, 193]),
                   array([165, 157,  52]),
                   array([239, 119,  83])]
                  

                  这篇关于使用 nditer 进行浅迭代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Running .jl file from R or Python(从 R 或 Python 运行 .jl 文件)
                  Running Julia .jl file in python(在 python 中运行 Julia .jl 文件)
                  Using PIP in a Azure WebApp(在 Azure WebApp 中使用 PIP)
                  How to run python3.7 based flask web api on azure(如何在 azure 上运行基于 python3.7 的烧瓶 web api)
                  Azure Python Web App Internal Server Error(Azure Python Web 应用程序内部服务器错误)
                  Run python dlib library on azure app service(在 azure app 服务上运行 python dlib 库)

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

                        <small id='29Uf8'></small><noframes id='29Uf8'>

                        • <bdo id='29Uf8'></bdo><ul id='29Uf8'></ul>