python用循环找最大值_并行化python中的嵌套for循环以查找最大值

在Python中,为了提高效率,作者尝试并行化一个嵌套循环来查找最大相似值。代码中,使用了`ThreadPoolExecutor`进行并行计算,并结合`concurrent.futures`库来处理结果。通过`itertools.permutations`生成所有可能的单词对,然后计算它们之间的相似度。最终找到每个单词的最大相似词及其相似度。
摘要由CSDN通过智能技术生成

I'm struggling for some time to improve the execution time of this piece of code. Since the calculations are really time-consuming I think that the best solution would be to parallelize the code.

The output could be also stored in memory, and written to a file afterwards.

I am new to both Python and parallelism, so I find it difficult to apply the concepts explained here and here. I also found this question, but I couldn't manage to figure out how to implement the same for my situation.

I am working on a Windows platform, using Python 3.4.

for i in range(0, len(unique_words)):

max_similarity = 0

max_similarity_word = ""

for j in range(0, len(unique_words)):

if not i == j:

similarity = calculate_similarity(global_map[unique_words[i]], global_map[unique_words[j]])

if similarity > m

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值