久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

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

    • <bdo id='BopR5'></bdo><ul id='BopR5'></ul>
    <legend id='BopR5'><style id='BopR5'><dir id='BopR5'><q id='BopR5'></q></dir></style></legend>
    <tfoot id='BopR5'></tfoot>
  • <small id='BopR5'></small><noframes id='BopR5'>

        Python - 定位最近的時間戳

        Python - Locating the closest timestamp(Python - 定位最近的時間戳)
      1. <small id='q2C0q'></small><noframes id='q2C0q'>

          • <bdo id='q2C0q'></bdo><ul id='q2C0q'></ul>

              • <legend id='q2C0q'><style id='q2C0q'><dir id='q2C0q'><q id='q2C0q'></q></dir></style></legend>
                <i id='q2C0q'><tr id='q2C0q'><dt id='q2C0q'><q id='q2C0q'><span id='q2C0q'><b id='q2C0q'><form id='q2C0q'><ins id='q2C0q'></ins><ul id='q2C0q'></ul><sub id='q2C0q'></sub></form><legend id='q2C0q'></legend><bdo id='q2C0q'><pre id='q2C0q'><center id='q2C0q'></center></pre></bdo></b><th id='q2C0q'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='q2C0q'><tfoot id='q2C0q'></tfoot><dl id='q2C0q'><fieldset id='q2C0q'></fieldset></dl></div>
                    <tbody id='q2C0q'></tbody>
                  <tfoot id='q2C0q'></tfoot>

                1. 本文介紹了Python - 定位最近的時間戳的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我有一個 Python 日期時間時間戳和一個大字典(索引),其中鍵是時間戳,值是我感興趣的其他一些信息.

                  I have a Python datetime timestamp and a large dict (index) where keys are timestamps and the values are some other information I'm interested in.

                  我需要盡可能高效地在索引中找到最接近時間戳的日期時間(鍵).

                  I need to find the datetime (the key) in index that is closest to timestamp, as efficiently as possible.

                  目前我正在做類似的事情:

                  At the moment I'm doing something like:

                  for timestamp in timestamps:
                      closestTimestamp = min(index,key=lambda datetime : abs(timestamp - datetime))
                  

                  這可行,但耗時太長 - 我的索引字典有數百萬個值,我正在搜索數千次.我對數據結構等很靈活 - 時間戳大致是連續的,所以我從第一個時間戳迭代到最后一個時間戳.同樣,我加載到字典中的文本文件中的時間戳也是連續的.

                  which works, but takes too long - my index dict has millions of values, and I'm doing the search thousands of times. I'm flexible with data structures and so on - the timestamps are roughly sequential, so that I'm iterating from the first to the last timestamps. Likewise the timestamps in the text file that I load into the dict are sequential.

                  任何關于優化的想法都將不勝感激.

                  Any ideas for optimisation would be greatly appreciated.

                  推薦答案

                  沒有組織字典以進行有效的接近未命中搜索.它們專為精確匹配而設計(使用 哈希表).

                  Dictionaries aren't organized for efficient near miss searches. They are designed for exact matches (using a hash table).

                  您最好維護一個單獨的、可快速搜索的有序結構.

                  You may be better-off maintaining a separate, fast-searchable ordered structure.

                  一個簡單的開始方法是使用 bisect 模塊對于快速 O(log N) 搜索但較慢 O(n) 插入:

                  A simple way to start off is to use the bisect module for fast O(log N) searches but slower O(n) insertions:

                  def nearest(ts):
                      # Given a presorted list of timestamps:  s = sorted(index)
                      i = bisect_left(s, ts)
                      return min(s[max(0, i-1): i+2], key=lambda t: abs(ts - t))
                  

                  適用于非靜態、動態更新的字典的更復雜的方法是使用 blist 它采用樹結構進行快速 O(log N) 插入和查找.只有當 dict 會隨著時間而改變時,你才需要這個.

                  A more sophisticated approach suitable for non-static, dynamically updated dicts, would be to use blist which employs a tree structure for fast O(log N) insertions and lookups. You only need this if the dict is going to change over time.

                  如果您想繼續使用基于字典的方法,請考慮將具有附近時間戳的條目聚集在一起的 dict-of-lists:

                  If you want to stay with a dictionary based approach, consider a dict-of-lists that clusters entries with nearby timestamps:

                   def get_closest_stamp(ts):
                        'Speed-up timestamp search by looking only at entries in the same hour'
                        hour = round_to_nearest_hour(ts)
                        cluster = daydict[hour]         # return a list of entries
                        return min(cluster, key=lambda t: abs(ts - t))
                  

                  注意,對于靠近集群邊界的準確結果,請在主集群和相鄰集群中存儲接近邊界的時間戳.

                  Note, for exact results near cluster boundaries, store close-to-the-boundary timestamps in both the primary cluster and the adjacent cluster.

                  這篇關于Python - 定位最近的時間戳的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  python: Two modules and classes with the same name under different packages(python:不同包下同名的兩個模塊和類)
                  Configuring Python to use additional locations for site-packages(配置 Python 以使用站點包的其他位置)
                  How to structure python packages without repeating top level name for import(如何在不重復導入頂級名稱的情況下構造python包)
                  Install python packages on OpenShift(在 OpenShift 上安裝 python 包)
                  How to refresh sys.path?(如何刷新 sys.path?)
                  Distribute a Python package with a compiled dynamic shared library(分發帶有已編譯動態共享庫的 Python 包)

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

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

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

                        <tbody id='iZ7Tb'></tbody>
                      • <bdo id='iZ7Tb'></bdo><ul id='iZ7Tb'></ul>
                            主站蜘蛛池模板: 国产视频精品视频 | 国产精品视频在线播放 | 99在线免费视频 | 麻豆天堂| 九色 在线| 欧美精品一区二区三区四区五区 | 一区二区三区四区五区在线视频 | 四虎在线播放 | 成在线人视频免费视频 | 久久伊人免费视频 | 女同久久 | 91精品国产一区二区三区 | 国产精品99久久久久久人 | 亚洲免费人成在线视频观看 | 高清av一区 | 91精品一区二区三区久久久久 | 毛片一区二区 | 国产精品久久久久久久模特 | 色欧美片视频在线观看 | 久久精品国产亚洲一区二区 | 91久久国产综合久久 | 亚洲大片在线观看 | 国产农村一级国产农村 | 天天操天天射天天 | 国产精品亚洲一区二区三区在线观看 | 在线观看免费福利 | 国产三级一区二区三区 | 亚洲欧美日韩精品久久亚洲区 | 日韩在线观看视频一区 | 99精品一区二区三区 | 视频一二三区 | 午夜精品在线观看 | 国产欧美一级 | 91视视频在线观看入口直接观看 | 久久久天天 | 免费观看的av | 日本视频中文字幕 | 午夜免费影视 | 久久久国产一区二区 | 性高湖久久久久久久久3小时 | 久久伊 |