其他分享
首页 > 其他分享> > 图神经网络GNN:创建图和展示图

图神经网络GNN:创建图和展示图

作者:互联网

'''
摘自https://docs.dgl.ai/en/0.6.x/guide_cn/graph-graphs-nodes-edges.html
'''

import dgl
import torch as th
import networkx as nx
import matplotlib.pyplot as plt

# 边 0->1, 0->2, 0->3, 1->3
u, v = th.tensor([0, 0, 0, 1]), th.tensor([1, 2, 3, 3])
graph = dgl.graph((u, v))
fig, ax = plt.subplots()
nx.draw(graph.to_networkx(), ax=ax)   # 将图转为networkx形式
ax.set_title('Graph')
plt.savefig('fig_graph.png')

  

结果:

 

标签:plt,th,展示,graph,神经网络,networkx,import,ax,GNN
来源: https://www.cnblogs.com/picassooo/p/15437773.html