1

I have list of edges from dynamic graph as shown below

G1=nx.read_edgelist('m_enron_employees_1Sorted.txt',create_using=nx.MultiGraph(), nodetype=int)
print(G1.edges())

[(13, 48), (13, 48), (13, 48), (13, 48), (13, 48), (13, 48), (13, 48), (13, 48), (13, 48), (13, 48), (13, 48), (13, 48), (13, 48), (13, 48), (13, 48), (13, 48), (13, 48), (13, 48), (13, 48), (13, 48), (13, 48), (13, 48), (13, 48), (13, 48), (13, 48), (13, 48), (13, 48), (13, 48), (13, 48), (13, 48), (13, 48), (13, 48), (13, 48), (13, 48), (13, 48), (13, 48), (13, 48), (13, 48), (13, 48), (13, 48), (13, 48), (13, 48), (13, 48), (13, 50), (13, 50), (13, 50), (13, 50), (13, 50), (13, 50), (13, 50), (13, 50), (13, 50), (13, 50), (13, 50), (13, 50), (13, 67), (13, 67), (13, 67), (13, 67), (13, 67), (13, 67), (13, 67), (13, 67), (13, 67), (13, 67), (13, 67), (13, 67), (13, 67), (13, 67), (13, 67), (13, 67), (13, 67), (13, 67), (13, 67), (13, 67), (13, 67), (13, 67), (13, 67), (13, 67), (13, 67), (13, 67), (13, 67), (13, 67), (13, 67), (13, 67), (13, 67), (13, 67), (13, 67), (13, 67), (13, 67), (13, 67), (13, 67), (13, 67), (13, 67), (13, 67), (13, 67), (13, 67), (13, 67), (13, 67), (13, 67), (13, 67), (13, 67), (13, 67), (13, 67), (13, 147), (13, 147), (13, 147), (13, 147), (13, 147), (13, 147), (13, 147), (13, 147), (13, 147), (13, 147), (13, 147), (13, 147), (13, 147), (13, 147), (13, 147), (13, 147), (13, 147), (13, 147)]

here I want to create a occurrence matrix, which capture number of times a specific edge appear

i tried the following optiom

count=0
tempo=-1
temp1=-1
app=[]
for edge in G1.edges():
    if((temp0,temp1)==(edge[0], edge[1]))
        count=count +1
    else:
      if count!=0:
          app.append((edge, count))
          temp0=edge[0]
          temp1=edge[1]
          count=1

However, this approach is not giving correct results

Any help will be much appreciated

TinaTz
  • 311
  • 3
  • 16

1 Answers1

1

Much easier to use set and the built-in count method:

>>> edges = [(13, 48), (13, 48), ... ]
>>>
>>> freqs = {edge: edges.count(edge) for edge in set(edges)}
>>> freqs
{(13, 67): 49, (13, 48): 43, (13, 50): 12, (13, 147): 18}
>>> max(freqs, key=lambda k: freqs[k])
(13, 67)

Not really sure what you mean by "occurrence matrix" since what it seems like you're doing is just counting the frequency of each edge.

ddejohn
  • 8,775
  • 3
  • 17
  • 30