一波儿networkx 读写edgelist,给节点加attribute的操作
一波儿networkx 读写edgelist,给节点加attribute的操作 read more: nx official: Reading and writing graphs import numpy as np import networkx as nx import operator G1 = nx.DiGraph(name='network1') # Directed Graph #networkx 导入edgelist with open(net1_path, 'r') as edgeReader: # 从文件中读取edgelist生成Graph of networkx for line in edgeReader.readlines(): edges_net1.append(tuple(map(int, line.strip().split(' ')))) G1.add_edges_from(edges_net1) print('\n== info of net1 original: ') print(nx.info(G1)) triad_list_net1 = [] for i in edges_net1: triad = tuple([i[0], i[1], i[0]+i[1]]) triad_list_net1.append(triad) # list of triads triad_list_net1.sort(key=operator.itemgetter(2)) # sort the list by the 3rd item of triad isgt_dict1 = dict(zip(G1.
…