Re: [networkx-discuss] remove all edges, or copy all node attributes

1,723 views
Skip to first unread message

Ben Edwards

unread,
Oct 1, 2012, 12:24:00 PM10/1/12
to networkx...@googlegroups.com
Some untested code but this should work, assuming G is your original graph:

>>> G_copy = nx.Graph() #or DiGraph or MultiGraph or MultiDiGraph depending on the original type of G
>>> G_copy.add_nodes_from(G.nodes(data=True))

Ben

On Mon, Oct 1, 2012 at 5:32 PM, Luuk van der Velden <l.j.j.van...@gmail.com> wrote:
Hi,
Lets say I have graph A and want a copy B without edges, but preserving node attributes

I could:
1 - make a copy B and then remove all edges from B
2 - create an empty graph B then add all nodes and attributes from A

any suggestions to this cleanly?

--
You received this message because you are subscribed to the Google Groups "networkx-discuss" group.
To view this discussion on the web visit https://groups.google.com/d/msg/networkx-discuss/-/PbVNMBVAvbMJ.
To post to this group, send email to networkx...@googlegroups.com.
To unsubscribe from this group, send email to networkx-discu...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/networkx-discuss?hl=en.

Luuk van der Velden

unread,
Oct 1, 2012, 12:27:53 PM10/1/12
to networkx...@googlegroups.com
thanks!, didn't data=True

also sorry for the double post, first time!
Reply all
Reply to author
Forward
0 new messages