MCPcopy Create free account
hub / github.com/easy-graph/Easy-Graph / average_degree

Function average_degree

easygraph/functions/basic/avg_degree.py:6–31  ·  view source on GitHub ↗

Returns the average degree of the graph. Parameters ---------- G : graph A EasyGraph graph Returns ------- average degree : float The average degree of the graph. Notes ----- Self loops are counted twice in the total degree of a node. Examp

(G)

Source from the content-addressed store, hash-verified

4
5
6def average_degree(G) -> float:
7 """Returns the average degree of the graph.
8
9 Parameters
10 ----------
11 G : graph
12 A EasyGraph graph
13
14 Returns
15 -------
16 average degree : float
17 The average degree of the graph.
18
19 Notes
20 -----
21 Self loops are counted twice in the total degree of a node.
22
23 Examples
24 --------
25 >>> G = eg.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc
26 >>> G.add_edge(1, 2)
27 >>> G.add_edge(2, 3)
28 >>> eg.average_degree(G)
29 1.3333333333333333
30 """
31 return G.number_of_edges() / G.number_of_nodes() * 2

Callers

nothing calls this directly

Calls 2

number_of_edgesMethod · 0.45
number_of_nodesMethod · 0.45

Tested by

no test coverage detected