• <legend id='r1vU8'><style id='r1vU8'><dir id='r1vU8'><q id='r1vU8'></q></dir></style></legend>
  • <tfoot id='r1vU8'></tfoot>

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

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

      1. 如何将一组重叠范围划分为非重叠范围?

        How to divide a set of overlapping ranges into non-overlapping ranges?(如何将一组重叠范围划分为非重叠范围?)
        <legend id='v5Iji'><style id='v5Iji'><dir id='v5Iji'><q id='v5Iji'></q></dir></style></legend>
            <bdo id='v5Iji'></bdo><ul id='v5Iji'></ul>
              <i id='v5Iji'><tr id='v5Iji'><dt id='v5Iji'><q id='v5Iji'><span id='v5Iji'><b id='v5Iji'><form id='v5Iji'><ins id='v5Iji'></ins><ul id='v5Iji'></ul><sub id='v5Iji'></sub></form><legend id='v5Iji'></legend><bdo id='v5Iji'><pre id='v5Iji'><center id='v5Iji'></center></pre></bdo></b><th id='v5Iji'></th></span></q></dt></tr></i><div id='v5Iji'><tfoot id='v5Iji'></tfoot><dl id='v5Iji'><fieldset id='v5Iji'></fieldset></dl></div>

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

                  <tbody id='v5Iji'></tbody>
                  <tfoot id='v5Iji'></tfoot>
                1. 本文介绍了如何将一组重叠范围划分为非重叠范围?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  假设您有一组范围:

                  • 0 - 100: 'a'
                  • 0 - 75:'b'
                  • 95 - 150: 'c'
                  • 120 - 130:'d'

                  显然,这些范围在某些点重叠.您将如何剖析这些范围以生成不重叠范围的列表,同时保留与其原始范围相关的信息(在本例中为范围后面的字母)?

                  Obviously, these ranges overlap at certain points. How would you dissect these ranges to produce a list of non-overlapping ranges, while retaining information associated with their original range (in this case, the letter after the range)?

                  例如上面运行算法后的结果是:

                  For example, the results of the above after running the algorithm would be:

                  • 0 - 75:'a'、'b'
                  • 76 - 94: 'a'
                  • 95 - 100:'a'、'c'
                  • 101 - 119:'c'
                  • 120 - 130:'c'、'd'
                  • 131 - 150:'c'

                  推荐答案

                  我在编写混合(部分重叠)音频样本的程序时遇到了同样的问题.

                  I had the same question when writing a program to mix (partly overlapping) audio samples.

                  我所做的是将开始事件"和停止事件"(针对每个项目)添加到列表中,按时间点对列表进行排序,然后按顺序处理.你可以做同样的事情,除了使用整数点而不是时间,而不是混合声音,你将添加符号到与范围相对应的集合中.是生成空范围还是忽略它们都是可选的.

                  What I did was add an "start event" and "stop event" (for each item) to a list, sort the list by time point, and then process it in order. You could do the same, except using an integer point instead of a time, and instead of mixing sounds you'd be adding symbols to the set corresponding to a range. Whether you'd generate empty ranges or just omit them would be optional.

                  编辑也许一些代码...

                  # input = list of (start, stop, symbol) tuples
                  points = [] # list of (offset, plus/minus, symbol) tuples
                  for start,stop,symbol in input:
                      points.append((start,'+',symbol))
                      points.append((stop,'-',symbol))
                  points.sort()
                  
                  ranges = [] # output list of (start, stop, symbol_set) tuples
                  current_set = set()
                  last_start = None
                  for offset,pm,symbol in points:
                      if pm == '+':
                           if last_start is not None:
                               #TODO avoid outputting empty or trivial ranges
                               ranges.append((last_start,offset-1,current_set))
                           current_set.add(symbol)
                           last_start = offset
                      elif pm == '-':
                           # Getting a minus without a last_start is unpossible here, so not handled
                           ranges.append((last_start,offset-1,current_set))
                           current_set.remove(symbol)
                           last_start = offset
                  
                  # Finish off
                  if last_start is not None:
                      ranges.append((last_start,offset-1,current_set))
                  

                  显然,完全未经测试.

                  这篇关于如何将一组重叠范围划分为非重叠范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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='ujXli'></bdo><ul id='ujXli'></ul>
                      • <tfoot id='ujXli'></tfoot>
                          <tbody id='ujXli'></tbody>

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

                        1. <legend id='ujXli'><style id='ujXli'><dir id='ujXli'><q id='ujXli'></q></dir></style></legend>

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