Networkx degree method did not produce, I think it

I ran the following script:

import networkx as nx
import matplotlib.pyplot as plt

G = nx.Graph()
G.add_edge(1, 1, weight=2)
G.add_edge(1, 3, weight=2)
G.add_edge(1, 4, weight=1)
G.add_edge(1, 5, weight=5)
G.add_edge(2, 3, weight=3)
G.add_edge(2, 4, weight=2)
G.add_edge(3, 5, weight=4)

d = G.degree(1)

print G.edge[1]
print "Degree of node 1:", \
    G.degree(1)
print "Weighted degree of node 1:", \
    G.degree(1, weight='weight')

nx.draw(G)
plt.show()

Conclusion:

{1: {'weight': 2}, 3: {'weight': 2}, 4: {'weight': 1}, 5: {'weight': 5}}
Weighted degree: 5
Weighted degree: 12

And the picture looks like this:

degree of the graph

What bothers me:

Since there are nodes 4 adjacent to node 1 (including itself), why is degree 5 ?

Since the total weight of neighboring edges of node 1 is 10 (2 + 2 + 1 + 5), why is the method of degree 12

thank

+4
source share
2 answers

For an undirected graph, the degree of a vertex is equal to the number of adjacent vertices.

A special case is the cycle , . , . , "" , , , .

+6

,

( ) , , , . ( )

So G.degree(1) 5, 1 1 . , 12 10, 1 node 2.

+3

Source: https://habr.com/ru/post/1537379/


All Articles