numpy for循环并行化更快Python [已关闭]

5jvtdoz2  于 2023-06-23  发布在  Python
关注(0)|答案(1)|浏览(80)

已关闭,此问题需要details or clarity。目前不接受答复。
**想改善这个问题吗?**通过editing this post添加详细信息并澄清问题。

5天前关闭。
Improve this question
早上好,请我用Python来加速我的应用程序我有一个旧的,他们使用多线程技术来加速过程,但性能比正常调用慢,我认为问题来自头顶,所以哪种技术建议我加速这些,除了我不知道哪种类型的数据,我在它上面循环了一些时间列表,字典....及其他
例如SDS中的SD
我不知道我循环的sds的类型

for sdg in sdgs:

mydata = self.get_id(sdg, n_variable, _del, new_split[1])
  • 我尝试使用池进行多处理,但变得更慢
  • 我也试过numpy,但正如我所说,我不知道什么是sd的类型

非常感谢

zbwhf8kr

zbwhf8kr1#

from multiprocessing import Pool
# Function to process each item in the iterable\
def process_data(sdg):
# Process your data here
mydata = self.get_id(sdg, n_variable, _del, new_split[1])
return mydata
if __name__ == '__main__':
# Create a pool of worker processe
pool = Pool()  # By default, it will use the number of CPU cores available

# Distribute the work among the workers and retrieve the results
results = pool.map(process_data, sds)  # sds is your iterable
# Process the results as needed
for result in results:

相关问题