MCPcopy
hub / github.com/networkx/networkx / degree

Method degree

networkx/classes/graph.py:1511–1546  ·  view source on GitHub ↗

A DegreeView for the Graph as G.degree or G.degree(). The node degree is the number of edges adjacent to the node. The weighted node degree is the sum of the edge weights for edges incident to that node. This object provides an iterator for (node, degree) as well as

(self)

Source from the content-addressed store, hash-verified

1509
1510 @cached_property
1511 def degree(self):
1512 """A DegreeView for the Graph as G.degree or G.degree().
1513
1514 The node degree is the number of edges adjacent to the node.
1515 The weighted node degree is the sum of the edge weights for
1516 edges incident to that node.
1517
1518 This object provides an iterator for (node, degree) as well as
1519 lookup for the degree for a single node.
1520
1521 Parameters
1522 ----------
1523 nbunch : single node, container, or all nodes (default= all nodes)
1524 The view will only report edges incident to these nodes.
1525
1526 weight : string or None, optional (default=None)
1527 The name of an edge attribute that holds the numerical value used
1528 as a weight. If None, then each edge has weight 1.
1529 The degree is the sum of the edge weights adjacent to the node.
1530
1531 Returns
1532 -------
1533 DegreeView or int
1534 If multiple nodes are requested (the default), returns a `DegreeView`
1535 mapping nodes to their degree.
1536 If a single node is requested, returns the degree of the node as an integer.
1537
1538 Examples
1539 --------
1540 >>> G = nx.path_graph(4) # or DiGraph, MultiGraph, MultiDiGraph, etc
1541 >>> G.degree[0] # node 0 has degree 1
1542 1
1543 >>> list(G.degree([0, 1, 2]))
1544 [(0, 1), (1, 2), (2, 2)]
1545 """
1546 return DegreeView(self)
1547
1548 def clear(self):
1549 """Remove all nodes and edges from the graph.

Callers 15

sizeMethod · 0.95
test_selfloop_degreeMethod · 0.95
test_weighted_degreeMethod · 0.95
LFR_benchmark_graphFunction · 0.95
test_single_nodeMethod · 0.95
test_four_cliqueFunction · 0.95
setup_classMethod · 0.95
pseudo_peripheral_nodeFunction · 0.45
smallest_degreeFunction · 0.45
degreeFunction · 0.45

Calls 1

DegreeViewClass · 0.90

Tested by 15

test_selfloop_degreeMethod · 0.76
test_weighted_degreeMethod · 0.76
test_single_nodeMethod · 0.76
test_four_cliqueFunction · 0.76
setup_classMethod · 0.76
smallest_degreeFunction · 0.36
test_degreeMethod · 0.36
test_hidden_nodesMethod · 0.36
test_hidden_edgesMethod · 0.36
test_shown_nodeMethod · 0.36
test_shown_edgesMethod · 0.36
test_inout_degreeMethod · 0.36