-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcount_from_edgelist.py
43 lines (31 loc) · 962 Bytes
/
count_from_edgelist.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# -*- coding: utf-8 -*-
"""
Created on Wed Apr 27 17:53:33 2022
@author: Paolo
bipartite to normal
"""
from timeit import default_timer as timer
import re
import pickle
import os
from collections import Counter, defaultdict
import numpy as np
input_file = "tmp/complete_local_bigraph.txt"
output_bigraph = "counted_bigraph.txt"
with open(input_file, "r") as infile:
with open(output_bigraph, "w") as outfile:
tmp_val = 0
last_n1 = -1
last_n2 = -1
for line in infile:
linesplit = line.split(" ")
n1 = linesplit[0]
n2 = linesplit[1]
val = int(linesplit[2])
if n2 != last_n2 or n1 != last_n1:
outfile.write(f"{last_n1} {last_n2} {tmp_val}\n")
last_n2 = n2
tmp_val = 0
if n1 != last_n1:
last_n1 = n1
tmp_val += val