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' 包含整个 a['t1'] 和键 '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