Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Networkx duplicate edges

If the same edge is added twice to the networkx edge data structure, will it then have two edges between the nodes or still just one? For example, would a spring layout show the nodes converge more with edges [(a,b),(a,b),(a,b),(a,b)] than [(a,b),(a,b)]? If I want to weight the edge, how would I go about it?

like image 527
user0 Avatar asked Feb 12 '15 21:02

user0


People also ask

What is Multidigraph?

A multidigraph is a directed graph which is permitted to have multiple arcs, i.e., arcs with the same source and target nodes. A multidigraph G is an ordered pair G := (V, A) with. V a set of vertices or nodes, A a multiset of ordered pairs of vertices called directed edges, arcs or arrows.

Are self loops allowed in MultiGraph?

A MultiGraph holds undirected edges. Self loops are allowed.

What is a DiGraph in Networkx?

A DiGraph stores nodes and edges with optional data, or attributes. DiGraphs hold directed edges. Self loops are allowed but multiple (parallel) edges are not. Nodes can be arbitrary (hashable) Python objects with optional key/value attributes.

How do I add edges to Networkx?

Add an edge between u and v. The nodes u and v will be automatically added if they are not already in the graph. Edge attributes can be specified with keywords or by directly accessing the edge's attribute dictionary.


1 Answers

You can test it pretty quickly, but it only adds them once. Edges and nodes are represented as a dictionaries inside the graph structure, and they are only added if they don't actually exist.

For already existing edges, adding them again has no effect.

like image 68
Imanol Luengo Avatar answered Sep 18 '22 19:09

Imanol Luengo