1

さて、ここで問題です!
私はこのような辞書を作成しました

a={'t1':[{seta1},{seta2},{seta3},{seta4}],
   't2':[{setb1},{setb2},{setb3},{setb4}],
    .
    .
    .
   't100':[{setz1},{setz2},{setz3},{setz4}]}

ここで、't1'、't2'、....、't100' はタイムスタンプであり、{set1}、{set2}、{set3}、{set4} はそれぞれのタイムスタンプでのクラスターの互いに素なセットです。

今、タイムスタンプ全体で、すべてのセットセットと他のすべてのセットとの交差点を見つけたいと思っています。すなわち、仮定

b={}   # is my resulting dictionary

最初は b は空なので、'b' にはキー 't1' を持つ a['t1'] 全体が含まれます

b['t1']=a['t1'] #isn't this a deep copy? cos i replicating the values. Is there a way to achieve a shallow copy? thought of using .copy() and .update() method but couldn't figure out any possible way.

反復が進むにつれて、交差点を見つけて、結果の辞書を次のように更新します。

k=[i&j for i in a[key1] for j in b[key2]]

#if intersections between a and b are empty sets, then i will create 'key1' in b and put the corresponding value of key1 in b
#if key1 is already present in b, then i will append the a[key1] value into b[key1] and remove the corresponding value from a[key1]

#if the intersections are found, and the length of each intersection is >2, i will do something like this
b[key2+','+key1] not in b.keys(): 
  b[key2+','+key1]=[] #b[t1,t2]=non-empty intersections whose length is >2
b[key2+','+key1]=k #where k holds the intersection and the empty sets and intersections with length one are removed before this stage    

seta1、seta2、seta3 などをそれぞれ持っているとします。それぞれ 100 個の要素を持つこと
は、交差点を非常に集中的に見つけることではありませんか? (100*100) 交差点を簡単に見つける効率的な方法はありますか? 強度を下げる方法は?交差点の最悪のシナリオはどこかで読んだと思います

     O(len(s)*len(t))

要約すると:

  • 簡単な方法で交差点を見つけるには? numpy の intersect1d はこれより優れていますか?
  • 計算のためのより良いデータ構造はありますか? (私はヒープが選択だと思っていましたが、挿入するたびにヒープツリーを再配置して「親の支配特性」を達成する必要があります。他の提案はありますか?)
  • あるディクショナリから別のディクショナリへの特定のキーと値のペアの浅いコピーを実現します。

どんな助けでも大歓迎です.! :) 前もってありがとう!:) :)

4

0 に答える 0