pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

<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="suqqam6" 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="uwqiece" 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="kau2skm" 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>
                            主站蜘蛛池模板: 比亚迪叉车-比亚迪电动叉车堆垛车托盘车仓储叉车价格多少钱报价 磁力去毛刺机_去毛刺磁力抛光机_磁力光饰机_磁力滚抛机_精密金属零件去毛刺机厂家-冠古科技 | 电缆隧道在线监测-智慧配电站房-升压站在线监测-江苏久创电气科技有限公司 | 小型气象站_车载气象站_便携气象站-山东风途物联网 | 防渗膜厂家|养殖防渗膜|水产养殖防渗膜-泰安佳路通工程材料有限公司 | H型钢切割机,相贯线切割机,数控钻床,数控平面钻,钢结构设备,槽钢切割机,角钢切割机,翻转机,拼焊矫一体机 | 【铜排折弯机,钢丝折弯成型机,汽车发泡钢丝折弯机,线材折弯机厂家,线材成型机,铁线折弯机】贝朗折弯机厂家_东莞市贝朗自动化设备有限公司 | 楼梯定制_楼梯设计施工厂家_楼梯扶手安装制作-北京凌步楼梯 | 免费B2B信息推广发布平台 - 推发网 | GEDORE扭力螺丝刀-GORDON防静电刷-CHEMTRONICS吸锡线-上海卓君电子有限公司 | 岛津二手液相色谱仪,岛津10A液相,安捷伦二手液相,安捷伦1100液相-杭州森尼欧科学仪器有限公司 | 多功能真空滤油机_润滑油全自动滤油机_高效真空滤油机价格-重庆润华通驰 | 电加热导热油炉-空气加热器-导热油加热器-翅片电加热管-科安达机械 | 上海赞永| 房在线-免费房产管理系统软件-二手房中介房屋房源管理系统软件 | 东莞动力锂电池保护板_BMS智能软件保护板_锂电池主动均衡保护板-东莞市倡芯电子科技有限公司 | 流量检测仪-气密性检测装置-密封性试验仪-东莞市奥图自动化科技有限公司 | 玉米深加工设备-玉米深加工机械-新型玉米工机械生产厂家-河南粮院机械制造有限公司 | 国际线缆连接网 - 连接器_线缆线束加工行业门户网站 | 浇注料-高铝砖耐火砖-郑州凯瑞得窑炉耐火材料有限公司 | PC构件-PC预制构件-构件设计-建筑预制构件-PC构件厂-锦萧新材料科技(浙江)股份有限公司 | 硫化罐_蒸汽硫化罐_大型硫化罐-山东鑫泰鑫智能装备有限公司 | 通信天线厂家_室分八木天线_对数周期天线_天线加工厂_林创天线源头厂家 | 365文案网_全网创意文案句子素材站 | 首页-恒温恒湿试验箱_恒温恒湿箱_高低温试验箱_高低温交变湿热试验箱_苏州正合 | 胀套-锁紧盘-风电锁紧盘-蛇形联轴器「厂家」-瑞安市宝德隆机械配件有限公司 | 旗杆生产厂家_不锈钢锥形旗杆价格_铝合金电动旗杆-上海锥升金属科技有限公司 | 上海乾拓贸易有限公司-日本SMC电磁阀_德国FESTO电磁阀_德国FESTO气缸 | 标准光源箱|对色灯箱|色差仪|光泽度仪|涂层测厚仪_HRC大品牌生产厂家 | 量子管通环-自清洗过滤器-全自动反冲洗过滤器-北京罗伦过滤技术集团有限公司 | 除甲醛公司-甲醛检测治理-杭州创绿家环保科技有限公司-室内空气净化十大品牌 | 无锡不干胶标签,卷筒标签,无锡瑞彩包装材料有限公司 | 工控机-图像采集卡-PoE网卡-人工智能-工业主板-深圳朗锐智科 | sfp光模块,高速万兆光模块工厂-性价比更高的光纤模块制造商-武汉恒泰通 | 垃圾清运公司_环卫保洁公司_市政道路保洁公司-华富环境 | 多物理场仿真软件_电磁仿真软件_EDA多物理场仿真软件 - 裕兴木兰 | 检验科改造施工_DSA手术室净化_导管室装修_成都特殊科室建设厂家_医疗净化工程公司_四川华锐 | 美能达分光测色仪_爱色丽分光测色仪-苏州方特电子科技有限公司 | 地磅-电子地磅维修-电子吊秤-汽车衡-无人值守系统-公路治超-鹰牌衡器 | 骨密度仪-骨密度测定仪-超声骨密度仪-骨龄测定仪-天津开发区圣鸿医疗器械有限公司 | 衢州装饰公司|装潢公司|办公楼装修|排屋装修|别墅装修-衢州佳盛装饰 | RTO换向阀_VOC高温阀门_加热炉切断阀_双偏心软密封蝶阀_煤气蝶阀_提升阀-湖北霍科德阀门有限公司 |