What#39;s the fastest way to compare two large lists of 1#39;s amp; 0#39;s and return the difference count/percentage?(比较两个大的 1 和 1 列表的最快方法是什么?0 并返回差异计数/百分比?)
问题描述
我需要一种方法来快速返回两个大列表之间的差异数.每个列表项的内容为 1 或 0(单个整数),每个列表中的项数始终为 307200.
I'm in need of a method to quickly return the number of differences between two large lists. The contents of each list item is either 1 or 0 (single integers), and the amount of items in each list will always be 307200.
这是我当前代码的示例:
This is a sample of my current code:
上述方法有效,但对于我的目的来说太慢了.我想知道是否有更快的方法来获取列表之间的差异数量,或者差异项目的百分比?
The above works but it is way too slow for my purposes. What I would like to know is if there is a quicker way to obtain the number of differences between lists, or the percentage of items that differ?
我在这个站点上查看了一些类似的线程,但它们的工作方式似乎与我想要的略有不同,并且 set() 示例似乎不适用于我的目的.:P
I have looked at a few similar threads on this site but they all seem to work slightly different from what I want, and the set() examples don't seem to work for my purposes. :P
推荐答案
如果你使用 NumPy,你至少可以获得 10 倍的加速数组而不是列表.
You can get at least another 10X speedup if you use NumPy arrays instead of lists.
这篇关于比较两个大的 1 和 1 列表的最快方法是什么?0 并返回差异计数/百分比?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!