Relative Content

Tag Archive for pythonnetworkx

Issue with NetworkX coloring nodes correctly

Good afternoon,
I amc currently trying to color nodes on a graph using a passed in node array. I have a function that gets called multiple times on the same graph and depending on the colors passed in, i want the nodes colored differently.

Networkx: convert a MultiDiGraph to a DiGraph while summing up the weights of multiple edges between the same pair of nodes

I have a MultiDiGraph that is created in a “clean” way, but then goes over several graph transformations (node merges) which may result in multiple edges between the same pair of nodes u and v (in the same direction u -> v), all having weights that may even have the same value. I want to transform the MultiDiGraph into a DiGraph such that the single resulting edge between u -> v has a weight equal to the sum of weights of the original u -> v edges in the MultiDiGraph. I understand the default behavior is to keep only the latest edge added between u and v. Is there any option where the conversion actually calculates the weight-sum and uses that as the final weight? (seems to me that this would actually be the most desired behavior). Is “manually” traversing nodes and edges and create the DiGraph the only way to achieve this?

Cumulative weight

I have a water pipe network where each node is a house and each edge is a pipe connecting houses. The edges have a water volume as an attribute.