Skip to content

Commit

Permalink
Add docstring example for attr transfer to linegraph. (#5698)
Browse files Browse the repository at this point in the history
Co-authored-by: Dan Schult <dschult@colgate.edu>

Co-authored-by: Dan Schult <dschult@colgate.edu>
  • Loading branch information
rossbar and dschult committed Jun 7, 2022
1 parent 9d462e0 commit 0bc0756
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions networkx/generators/line.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ def line_graph(G, create_using=None):
>>> print(sorted(map(sorted, L.edges()))) # makes a 3-clique, K3
[[(0, 1), (0, 2)], [(0, 1), (0, 3)], [(0, 2), (0, 3)]]
Edge attributes from `G` are not copied over as node attributes in `L`, but
attributes can be copied manually:
>>> G = nx.path_graph(4)
>>> G.add_edges_from((u, v, {"tot": u+v}) for u, v in G.edges)
>>> G.edges(data=True)
EdgeDataView([(0, 1, {'tot': 1}), (1, 2, {'tot': 3}), (2, 3, {'tot': 5})])
>>> H = nx.line_graph(G)
>>> H.add_nodes_from((node, G.edges[node]) for node in H)
>>> H.nodes(data=True)
NodeDataView({(0, 1): {'tot': 1}, (2, 3): {'tot': 5}, (1, 2): {'tot': 3}})
Notes
-----
Graph, node, and edge data are not propagated to the new graph. For
Expand Down

0 comments on commit 0bc0756

Please sign in to comment.