dynamicalab.merge_duplicated_nodes

dynamicalab.merge_duplicated_nodes(G, based_on='name', get_node_attr_fct=None, relabel=False)[source]

Merge duplicated nodes based on either a key attribute (based_on) or using a certain function to extract the node key.

Parameters

G : nx.Graph
Networkx graph
based_on : String
If not None, will be used to extract node identity as node["attr_dict"][based_on]. If None, the get_node_attr_fct will be used.
get_node_attr_fct : method
If based_on is None, get_node_attr_fct is used to extract node identity as get_node_attr_fct(node).
relabel : bool
If True, relabel the nodes to be between 0 and the new number of nodes. Else, keep the original relabeling.

Returns

Network graph

if relabel==True, the mapping will be returned : G, mapping