简体   繁体   English

如何优化这段代码的运行时间?

[英]How to optimize the running time of this code?

This intersection two-dimensional array represents the number of times that scenic spot B also appeared when scenic spot A appeared.这个交集二维数组表示当景点A出现时,景点B也出现的次数。 Now this code takes about 1 minute and 30 seconds to get the result.现在这段代码需要大约 1 分 30 秒才能得到结果。 Is it possible to get the result of this code in 10 seconds?是否有可能在 10 秒内得到这段代码的结果?

for a in range ((len(user_record[0]))):#len(user_record[0]) is 1136
    b = 0
    for b in range ((len(user_record[0]))): #len(user_record[0]) is 1136
        c = 0
        Intersection[a][b] = 0
        for c in range (len(user_record)): #len(user_record) is 31
            Intersection[a][b] = Intersection[a][b] + user_record[c-1][a] * user_record[c-1][b]

I suggest moving your data to numpy structures.我建议将您的数据移动到 numpy 结构。 After that, there are many functions like intersect1d that resolve this kind of problems in the right manner.在那之后,有许多像intersect1d这样的函数以正确的方式解决了这类问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM