小编Jaq*_*aqo的帖子

具有更新队列和输出队列的Python多处理

如何编写使用两个队列的Python多进程脚本?

  1. 一个作为工作队列,从一些数据开始,然后根据要并行化的功能的条件,即时接收其他任务,
  2. 另一个收集结果并用于在处理完成后记下结果。

我基本上需要根据我在初始项目中发现的内容,在工作队列中添加更多任务。我在下面发布的示例很愚蠢(我可以随意更改项目并将其直接放在输出Queue中),但是它的机制很明确,反映了我需要开发的概念的一部分。

在此,我尝试:

import multiprocessing as mp

def worker(working_queue, output_queue):
    item = working_queue.get() #I take an item from the working queue
    if item % 2 == 0:
        output_queue.put(item**2) # If I like it, I do something with it and conserve the result.
    else:
        working_queue.put(item+1) # If there is something missing, I do something with it and leave the result in the working queue 

if __name__ == '__main__':
    static_input = range(100)    
    working_q = mp.Queue()
    output_q = mp.Queue()
    for i …
Run Code Online (Sandbox Code Playgroud)

python multiprocessing

5
推荐指数
2
解决办法
1万
查看次数

在两个 numpy 的匀称对象数组上应用成对匀称函数

我有两个不同长度的数组。一个包含匀称的多边形,另一个包含匀称的点。我想为两个数组中的每个可能的元素组合运行 a_polygon.contains(a_point) 匀称的函数。

我正在看这篇文章,因为构建一个包含行中所有可能组合的两列矩阵可能是一个理想的中间步骤。但是当输入数据很大时,'cartersian(arrays)' 函数中的循环可能会影响性能。

我尝试广播其中一个数组,然后应用 shapely 函数:

Polygons_array[:,newaxis].contains(Points_array)
Run Code Online (Sandbox Code Playgroud)

但这当然是行不通的。我知道最近发布的 geopandas 库,但它不是我的 Canopy 安装的一个选项。

python arrays numpy shapely

4
推荐指数
1
解决办法
2127
查看次数

标签 统计

python ×2

arrays ×1

multiprocessing ×1

numpy ×1

shapely ×1