• <small id='MslkP'></small><noframes id='MslkP'>

    <i id='MslkP'><tr id='MslkP'><dt id='MslkP'><q id='MslkP'><span id='MslkP'><b id='MslkP'><form id='MslkP'><ins id='MslkP'></ins><ul id='MslkP'></ul><sub id='MslkP'></sub></form><legend id='MslkP'></legend><bdo id='MslkP'><pre id='MslkP'><center id='MslkP'></center></pre></bdo></b><th id='MslkP'></th></span></q></dt></tr></i><div id='MslkP'><tfoot id='MslkP'></tfoot><dl id='MslkP'><fieldset id='MslkP'></fieldset></dl></div>
        <tfoot id='MslkP'></tfoot>
        <legend id='MslkP'><style id='MslkP'><dir id='MslkP'><q id='MslkP'></q></dir></style></legend>
          <bdo id='MslkP'></bdo><ul id='MslkP'></ul>

      1. 比较两个大的 1 和 1 列表的最快方法是什么?0 并返回差异计数/百分比?

        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 并返回差异计数/百分比?)

          <bdo id='qRjow'></bdo><ul id='qRjow'></ul>
            <tfoot id='qRjow'></tfoot>

              <small id='qRjow'></small><noframes id='qRjow'>

            • <i id='qRjow'><tr id='qRjow'><dt id='qRjow'><q id='qRjow'><span id='qRjow'><b id='qRjow'><form id='qRjow'><ins id='qRjow'></ins><ul id='qRjow'></ul><sub id='qRjow'></sub></form><legend id='qRjow'></legend><bdo id='qRjow'><pre id='qRjow'><center id='qRjow'></center></pre></bdo></b><th id='qRjow'></th></span></q></dt></tr></i><div id='qRjow'><tfoot id='qRjow'></tfoot><dl id='qRjow'><fieldset id='qRjow'></fieldset></dl></div>

                <tbody id='qRjow'></tbody>
              • <legend id='qRjow'><style id='qRjow'><dir id='qRjow'><q id='qRjow'></q></dir></style></legend>

                  本文介绍了比较两个大的 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:

                  list1 = <list1> # should be a list of integers containing 1's or 0's
                  list2 = <list2> # same rule as above, in a slightly different order
                  
                  diffCount = 0
                  for index, item in enumerate(list1):
                      if item != list2[index]:
                          diffCount += 1
                  
                  percent = float(diffCount) / float(307200)
                  

                  上述方法有效,但对于我的目的来说太慢了.我想知道是否有更快的方法来获取列表之间的差异数量,或者差异项目的百分比?

                  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.

                  import random
                  import time
                  import numpy as np
                  list1 = [random.choice((0,1)) for x in xrange(307200)]
                  list2 = [random.choice((0,1)) for x in xrange(307200)]
                  a1 = np.array(list1)
                  a2 = np.array(list2)
                  
                  def foo1():
                      start = time.clock()
                      counter = 0
                      for i in xrange(307200):
                          if list1[i] != list2[i]:
                              counter += 1
                      print "%d, %f" % (counter, time.clock()-start)
                  
                  def foo2():
                      start = time.clock()
                      ct = np.sum(a1!=a2)
                      print "%d, %f" % (ct, time.clock()-start)
                  
                  foo1() #153490, 0.096215
                  foo2() #153490, 0.010224
                  

                  这篇关于比较两个大的 1 和 1 列表的最快方法是什么?0 并返回差异计数/百分比?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  What happens when you compare 2 pandas Series(当你比较 2 个 pandas 系列时会发生什么)
                  Quickly find differences between two large text files(快速查找两个大文本文件之间的差异)
                  Python - Compare 2 files and output differences(Python - 比较 2 个文件和输出差异)
                  Why do comparisions between very large float values fail in python?(为什么在 python 中非常大的浮点值之间的比较会失败?)
                  Dictionary merge by updating but not overwriting if value exists(字典通过更新合并,但如果值存在则不覆盖)
                  Find entries of one text file in another file in python(在python中的另一个文件中查找一个文本文件的条目)
                    <bdo id='ucH9U'></bdo><ul id='ucH9U'></ul>

                        <i id='ucH9U'><tr id='ucH9U'><dt id='ucH9U'><q id='ucH9U'><span id='ucH9U'><b id='ucH9U'><form id='ucH9U'><ins id='ucH9U'></ins><ul id='ucH9U'></ul><sub id='ucH9U'></sub></form><legend id='ucH9U'></legend><bdo id='ucH9U'><pre id='ucH9U'><center id='ucH9U'></center></pre></bdo></b><th id='ucH9U'></th></span></q></dt></tr></i><div id='ucH9U'><tfoot id='ucH9U'></tfoot><dl id='ucH9U'><fieldset id='ucH9U'></fieldset></dl></div>

                        <small id='ucH9U'></small><noframes id='ucH9U'>

                        <legend id='ucH9U'><style id='ucH9U'><dir id='ucH9U'><q id='ucH9U'></q></dir></style></legend>

                          <tbody id='ucH9U'></tbody>
                      1. <tfoot id='ucH9U'></tfoot>