Accessing MultiGraph edge keys

730 views
Skip to first unread message

Brian Keegan

unread,
Apr 4, 2012, 7:48:23 PM4/4/12
to networkx...@googlegroups.com
I've created a multi-digraph with:

import networkx as nx
G=nx.MultiDiGraph()
# Loop to add many edges, update weights, add edges for other objects etc. 
G.add_edge(userID1,userID2,key=objectID,weight=1) 

My goal is to use the multigraph as a structure to store the data and then be able to extract subgraphs containing only edges sharing a common key, count how many users have relationships across object IDs, etc. These functions would (in my mind) require me to be able to access/report the key which defines the edge but G.edges(data=True)[0] doesn't report the key of a multi-edge. 

How can I get the key for this edge reported so that I can do other calculations with itemgetter, etc.?

Thanks!

Brian

--
Brian C. Keegan
Ph.D. Student - Media, Technology, & Society
School of Communication, Northwestern University

Science of Networks in Communities, Laboratory for Collaborative Technology

Brian Keegan

unread,
Apr 4, 2012, 7:57:24 PM4/4/12
to networkx...@googlegroups.com
I should have mentioned that I realize I could define an edge attribute which is the same as the key (objectID, in this case) to access, but this seems unnecessary and inefficient. But if that's the easiest solution, then let it be.

Dan Schult

unread,
Apr 4, 2012, 8:15:00 PM4/4/12
to networkx...@googlegroups.com
For a MultiGraph

G.edges(keys=True, data=True) 

returns a list of 4-tuples (u,v,key,data_dict)



--
You received this message because you are subscribed to the Google Groups "networkx-discuss" group.
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.

Brian Keegan

unread,
Apr 4, 2012, 8:18:06 PM4/4/12
to networkx...@googlegroups.com
Easy enough, thank you! Any chance this important bit of information could be added to the documentation?

Brian Keegan

unread,
Apr 4, 2012, 8:18:52 PM4/4/12
to networkx...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages