networkx

networkx edge-to-node node-to-edge representation

自作多情 提交于 2020-08-27 07:16:05
问题 There is a graph, G(e,v) with N nodes and M edges. Its distance matrix, D is a NxN matrix. Now let us imagine an alternative representation of this graph G'(e'=v,v'=e) , that is the nodes v' in G' are actually the edges in the graph G, keeping the connectivity the same. Now its distance matrix, D' is MxM. Is there any way already present in NetworkX to get this D'(MxM) from D(NxN)? 回答1: networkx has a function called line_graph() that appears to do what you're looking for. Here is an example

Removing self-loops from undirected networkx graph

不问归期 提交于 2020-08-24 06:46:21
问题 I have created a graph from list of nodes using networkx . It has self loops. How to remove them? Following is sample: import networkx as NX G=NX.Graph() G.add_edge(1,2) G.add_edge(1,1) print (G.edges()) [(1, 2), (1, 1)] I don't want (1, 1) edges. 回答1: In version 1.x (when I originally answered this question), it was: G.remove_edges_from(G.selfloop_edges()) If you're using 2.x try G.remove_edges_from(nx.selfloop_edges(G)) You need nx.selfloop_edges(G) because G.selfloop_edges() has been

Removing self-loops from undirected networkx graph

泪湿孤枕 提交于 2020-08-24 06:44:41
问题 I have created a graph from list of nodes using networkx . It has self loops. How to remove them? Following is sample: import networkx as NX G=NX.Graph() G.add_edge(1,2) G.add_edge(1,1) print (G.edges()) [(1, 2), (1, 1)] I don't want (1, 1) edges. 回答1: In version 1.x (when I originally answered this question), it was: G.remove_edges_from(G.selfloop_edges()) If you're using 2.x try G.remove_edges_from(nx.selfloop_edges(G)) You need nx.selfloop_edges(G) because G.selfloop_edges() has been

Removing self-loops from undirected networkx graph

a 夏天 提交于 2020-08-24 06:42:33
问题 I have created a graph from list of nodes using networkx . It has self loops. How to remove them? Following is sample: import networkx as NX G=NX.Graph() G.add_edge(1,2) G.add_edge(1,1) print (G.edges()) [(1, 2), (1, 1)] I don't want (1, 1) edges. 回答1: In version 1.x (when I originally answered this question), it was: G.remove_edges_from(G.selfloop_edges()) If you're using 2.x try G.remove_edges_from(nx.selfloop_edges(G)) You need nx.selfloop_edges(G) because G.selfloop_edges() has been

How to visualize (dendrogram) a dictionary of hierarchical items?

好久不见. 提交于 2020-08-22 19:20:32
问题 This is my first time of doing visualization from hierarchical data in dictionary format with Python. Last part of the data looks like this: d = {^2820: [^391, ^1024], ^2821: [^759, 'w', ^118, ^51], ^2822: [^291, 'o'], ^2823: [^25, ^64], ^2824: [^177, ^2459], ^2825: [^338, ^1946], ^2826: [^186, ^1511], ^2827: [^162, 'i']} So I have indices on lists referring back to the keys (index) of the dictionary. I suppose this could be used as a base structure for the visualization, please correct me if