DGL_子图
用途一:數據集太大,無法畫圖,取子圖看看是有向圖/無向圖
import dgl import matplotlib.pyplot as plt import networkx as nx G = dgl.DGLGraph() G.add_nodes(5) # G.add_edges([0, 1, 2, 3, 4], [1, 2, 3, 4, 0]) # 有向圖 G.add_edges([0, 1, 2, 3, 4, 1, 2, 3, 4, 0], [1, 2, 3, 4, 0, 0, 1, 2, 3, 4]) # 無向圖(雙向圖) SG = G.subgraph([0, 1, 4]) SG.nodes() # tensor([0, 1, 2]) SG.edges() # (tensor([0, 2]), tensor([1, 0])) SG.parent_nid # tensor([0, 1, 4]) SG.parent_eid # tensor([0, 4])nx_G1 = G.to_networkx() nx_G2 = SG.to_networkx() plt.subplot(121) nx.draw_shell(nx_G1, with_labels=True, font_weight='bold') # 節點按序排列 plt.subplot(122) nx.draw_shell(nx_G2, with_labels=True, font_weight='bold') # 節點按序排列 plt.show()有向圖的子圖是有向圖
無向圖的子圖是無向圖
總結
- 上一篇: Android官方开发文档Trainin
- 下一篇: Android官方开发文档Trainin