# Graph analysis : extract highly connected nodes in a weighted 2-group directed graph

I've a question regarding the extraction of highly connected nodes. My graph is directed graph with only two groups of nodes (X and Y). In the example below group X (node 0, 1, 2 and 3) points to group Y nodes (nodes A, 9 and C).

I would like to extract highly connected nodes taking into account the weight of each edges. In this example I would like to have :

[0, 1, 2, 3, A, B]

Any idea where to start ?

Thank you

• It looks like you forgot node 9. and based on the example weights, I think the correct ordering is [9, 0, 3, 1, 2, 'B', 'A'] unless I've misinterpreted your question. – ComplexGates Feb 23 '19 at 17:18

The concept you describe is called the weighted degree of the node.

Here is a quick snippet in python for your example:

import networkx as nx

G = nx.Graph()
G.add_weighted_edges_from([(0, 'A', 5), (1, 'A', 3), (2, 'A', 7), (3, 'A', 2), (1, 9, 2), (1, 'B', 5), (2, 'B', 3), (3, 'B', 6)])
weighted_degree = G.degree(weight='weight')

print(weighted_degree)
[(0, 5), ('A', 17), (1, 10), (2, 10), (3, 8), (9, 2), ('B', 14)]

print([x[0] for x in sorted(weighted_degree, key=lambda x:x[1])])
[9, 0, 3, 1, 2, 'B', 'A']