久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  • <small id='KJWXL'></small><noframes id='KJWXL'>

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

      <tfoot id='KJWXL'></tfoot>
        <bdo id='KJWXL'></bdo><ul id='KJWXL'></ul>

        我可以在 python 中創建共享的多數組或列表對象列

        Can I create a shared multiarray or lists of lists object in python for multiprocessing?(我可以在 python 中創建共享的多數組或列表對象列表以進行多處理嗎?)
          <tbody id='Bu0iw'></tbody>
        <i id='Bu0iw'><tr id='Bu0iw'><dt id='Bu0iw'><q id='Bu0iw'><span id='Bu0iw'><b id='Bu0iw'><form id='Bu0iw'><ins id='Bu0iw'></ins><ul id='Bu0iw'></ul><sub id='Bu0iw'></sub></form><legend id='Bu0iw'></legend><bdo id='Bu0iw'><pre id='Bu0iw'><center id='Bu0iw'></center></pre></bdo></b><th id='Bu0iw'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Bu0iw'><tfoot id='Bu0iw'></tfoot><dl id='Bu0iw'><fieldset id='Bu0iw'></fieldset></dl></div>

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

      1. <legend id='Bu0iw'><style id='Bu0iw'><dir id='Bu0iw'><q id='Bu0iw'></q></dir></style></legend>
      2. <tfoot id='Bu0iw'></tfoot>

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

                  本文介紹了我可以在 python 中創建共享的多數組或列表對象列表以進行多處理嗎?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  我需要創建一個多維數組或列表列表的共享對象,以便其他進程可以使用它.有沒有辦法創建它,因為我已經看到它是不可能的.我試過了:

                  from multiprocessing import Process, Value, Arrayarr = Array('i', range(10))arr[:][0, 1, 2, 3, 4, 5, 6, 7, 8, 9]arr[2]=[12,43]TypeError:需要一個整數

                  我聽說 numpy 數組可以是多數組和共享對象,如果以上不可能,有人可以告訴我如何使 numpy 數組成為共享對象嗎??

                  解決方案

                  將 numpy 數組變成共享對象(完整示例):

                  將 ctypes 導入為 c將 numpy 導入為 np將多處理導入為 mpn, m = 2, 3mp_arr = mp.Array(c.c_double, n*m) # 共享,可以從多個進程中使用# 然后在每個新進程中創建一個新的 numpy 數組,使用:arr = np.frombuffer(mp_arr.get_obj()) # mp_arr 和 arr 共享同一個內存# 讓它變成二維的b = arr.reshape((n,m)) # b 和 arr 共享同一個內存

                  如果您不需要 shared (如共享同一內存")對象并且僅可以從多個進程中使用的對象就足夠了,那么您可以使用 multiprocessing.經理:

                  from multiprocessing import Process, Manager定義 f(L):row = L[0] # 取第一行row.append(10) # 改變它L[0] = row #注意:重要:將行復制回來(否則為父#process 不會看到更改)如果 __name__ == '__main__':經理=經理()lst = manager.list()lst.append([1])lst.append([2, 3])print(lst) # before: [[1], [2, 3]]p = 進程(目標=f,args=(lst,))p.start()p.join()print(lst) # after: [[1, 10], [2, 3]]

                  來自文檔:p><塊引用>

                  服務器進程管理器比使用共享內存更靈活對象,因為它們可以支持任意對象類型.此外,單個管理器可以由不同的進程共享通過網絡的計算機.但是,它們比使用共享的要慢記憶.

                  I need to make a shared object of a multidimensional array or list of lists for it to be available to the other processes. Is there a way to create it as for what i have seen it is not possible. I have tried:

                  from multiprocessing import Process, Value, Array
                  arr = Array('i', range(10))
                  arr[:]
                  [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
                  arr[2]=[12,43]
                  TypeError: an integer is required
                  

                  I heard numpy array can be multiarray and a shared object, if above is not possible can someone tell me how to make a numpy array a shared object??

                  解決方案

                  To make a numpy array a shared object (full example):

                  import ctypes as c
                  import numpy as np
                  import multiprocessing as mp
                  
                  n, m = 2, 3
                  mp_arr = mp.Array(c.c_double, n*m) # shared, can be used from multiple processes
                  # then in each new process create a new numpy array using:
                  arr = np.frombuffer(mp_arr.get_obj()) # mp_arr and arr share the same memory
                  # make it two-dimensional
                  b = arr.reshape((n,m)) # b and arr share the same memory
                  

                  If you don't need a shared (as in "share the same memory") object and a mere object that can be used from multiple processes is enough then you could use multiprocessing.Manager:

                  from multiprocessing import Process, Manager
                  
                  def f(L):
                      row = L[0] # take the 1st row
                      row.append(10) # change it
                      L[0] = row #NOTE: important: copy the row back (otherwise parent
                                 #process won't see the changes)
                  
                  if __name__ == '__main__':
                      manager = Manager()
                  
                      lst = manager.list()
                      lst.append([1])
                      lst.append([2, 3])
                      print(lst) # before: [[1], [2, 3]]
                  
                      p = Process(target=f, args=(lst,))
                      p.start()
                      p.join()
                  
                      print(lst) # after: [[1, 10], [2, 3]]
                  

                  From the docs:

                  Server process managers are more flexible than using shared memory objects because they can be made to support arbitrary object types. Also, a single manager can be shared by processes on different computers over a network. They are, however, slower than using shared memory.

                  這篇關于我可以在 python 中創建共享的多數組或列表對象列表以進行多處理嗎?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  What exactly is Python multiprocessing Module#39;s .join() Method Doing?(Python 多處理模塊的 .join() 方法到底在做什么?)
                  Passing multiple parameters to pool.map() function in Python(在 Python 中將多個參數傳遞給 pool.map() 函數)
                  multiprocessing.pool.MaybeEncodingError: #39;TypeError(quot;cannot serialize #39;_io.BufferedReader#39; objectquot;,)#39;(multiprocessing.pool.MaybeEncodingError: TypeError(cannot serialize _io.BufferedReader object,)) - IT屋-程序員軟件開
                  Python Multiprocess Pool. How to exit the script when one of the worker process determines no more work needs to be done?(Python 多進程池.當其中一個工作進程確定不再需要完成工作時,如何退出腳本?) - IT屋-程序員
                  How do you pass a Queue reference to a function managed by pool.map_async()?(如何將隊列引用傳遞給 pool.map_async() 管理的函數?)
                  yet another confusion with multiprocessing error, #39;module#39; object has no attribute #39;f#39;(與多處理錯誤的另一個混淆,“模塊對象沒有屬性“f)

                    • <i id='2y3Q3'><tr id='2y3Q3'><dt id='2y3Q3'><q id='2y3Q3'><span id='2y3Q3'><b id='2y3Q3'><form id='2y3Q3'><ins id='2y3Q3'></ins><ul id='2y3Q3'></ul><sub id='2y3Q3'></sub></form><legend id='2y3Q3'></legend><bdo id='2y3Q3'><pre id='2y3Q3'><center id='2y3Q3'></center></pre></bdo></b><th id='2y3Q3'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='2y3Q3'><tfoot id='2y3Q3'></tfoot><dl id='2y3Q3'><fieldset id='2y3Q3'></fieldset></dl></div>
                        <bdo id='2y3Q3'></bdo><ul id='2y3Q3'></ul>

                          <tbody id='2y3Q3'></tbody>
                      • <tfoot id='2y3Q3'></tfoot>

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

                            <small id='2y3Q3'></small><noframes id='2y3Q3'>

                            主站蜘蛛池模板: 国产一区二区在线免费观看 | 九九热免费看 | 国产九九精品视频 | 精品久久国产 | 99免费精品 | 久久精品99国产精品日本 | 中文字幕蜜臀 | 久久久婷婷 | 日产精品久久久一区二区福利 | 人人澡人人爱 | 羞羞视频一区二区 | 国产成人精品免高潮在线观看 | 国产精品18hdxxxⅹ在线 | 国产亚洲一区二区三区在线观看 | 欧美一级二级三级 | 男女深夜网站 | av在线二区| 久久91精品国产一区二区三区 | 一区二区三区在线免费观看 | 国产精品成人一区二区三区 | 99re视频| 91精品一区二区三区久久久久 | 国产乱码久久久久久一区二区 | 亚州一区二区三区 | 免费一级片 | 久久精品网 | 2021天天干夜夜爽 | 精品视频久久久 | 欧美日韩免费在线 | 亚洲日本成人 | 视频一区在线 | 九九视频在线观看 | aaaa一级毛片| 中文字幕国产高清 | 欧美精品二区 | 韩国主播午夜大尺度福利 | 久久久久久久久久毛片 | 日韩一区二区在线视频 | 亚洲第一区久久 | 成人做爰69片免费观看 | 亚洲欧美日韩电影 |