dgl.DGLGraph.to_networkx¶
-
DGLGraph.
to_networkx
(node_attrs=None, edge_attrs=None)[source]¶ Convert to networkx graph.
The edge id will be saved as the ‘id’ edge attribute.
Parameters: - node_attrs (iterable of str, optional) – The node attributes to be copied.
- edge_attrs (iterable of str, optional) – The edge attributes to be copied.
Returns: The nx graph
Return type: Examples
Note
Here we use pytorch syntax for demo. The general idea applies to other frameworks with minor syntax change (e.g. replace
torch.tensor
withmxnet.ndarray
).>>> import torch as th >>> g = DGLGraph() >>> g.add_nodes(5, {'n1': th.randn(5, 10)}) >>> g.add_edges([0,1,3,4], [2,4,0,3], {'e1': th.randn(4, 6)}) >>> nxg = g.to_networkx(node_attrs=['n1'], edge_attrs=['e1'])