Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Line graph with attributes #4483

Closed
vymao opened this issue Dec 21, 2020 · 2 comments · Fixed by #5698
Closed

Line graph with attributes #4483

vymao opened this issue Dec 21, 2020 · 2 comments · Fixed by #5698

Comments

@vymao
Copy link

vymao commented Dec 21, 2020

If we have some graph with edge attributes, is it possible to generate the line graph somehow with the original edge attributes embedded into the line graph nodes? Would save a lot of hassle.

@dschult
Copy link
Member

dschult commented Dec 22, 2020

It looks like one additional line of code will transfer all the edge attributes of the original graph to the line graph as node attributes.

G = nx.path_graph(4)
G.add_edges_from((u, v, {'krill': u+v}) for u, v in G.edges)
H = nx.line_graph(G)
H.add_nodes_from((node, G.edges[node]) for node in H)

@rossbar
Copy link
Contributor

rossbar commented May 15, 2022

I think @dschult 's comment very nicely answers the question and IMO would be a nice addition to the docstring examples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

3 participants