读取文件

1.读取.gpickle

self.di_graph = nx.read_gpickle(f'{ROOT_DIR}/data/%s/graph.gpickle' % self.data_set)

2.读取.emb

list_of_files = glob.glob(f'{OUTPUT_DIR}/{data_set}*.emb') # /home/jovyan/work/GEM/assets/0.4.2/sd_sample_real_re_social.emb
latest_file = max(list_of_files, key=os.path.getctime)
tmp_data=pickle.load( open(latest_file, 'rb') )

df = pd.DataFrame(tmp_data, index=phone_md5_df['phone_md5'])
df.rename(columns=lambda x: 'emb'+str(x), inplace=True)

3.读取mat文件

import scipy.io
mat = scipy.io.loadmat('./Homo_sapiens.mat') --稀疏矩阵 <class 'dict'>

 

4.将edgelist转化为graph

G = loadGraphFromEdgeListTxt('./ca-HepTh.txt', directed=False)

#输出节点
with open('nodes_list.txt', 'w') as f:
for item in list(G.nodes()):
f.write(f"{item}\n")

G = nx.convert_node_labels_to_integers(G)

 

posted on 2019-09-11 13:53  happygril3  阅读(236)  评论(0)    收藏  举报

导航