NetworkX

Previous topic

networkx.LabeledGraph.number_of_selfloops

Next topic

networkx.LabeledGraph.degree_iter

Quick search

networkx.LabeledGraph.degree

LabeledGraph.degree(nbunch=None, with_labels=False, weighted=False)

Return the degree of a node or nodes.

The node degree is the number of edges adjacent to that node.

Parameters:

nbunch : list, iterable

A container of nodes that will be iterated through once (thus it should be an iterator or be iterable). Each element of the container should be a valid node type: any hashable type except None. If nbunch is None, return all edges data in the graph. Nodes in nbunch that are not in the graph will be (quietly) ignored.

with_labels : False|True

Return a list of degrees (False) or a dictionary of degrees keyed by node (True).

weighted : False|True

If the graph is weighted return the weighted degree (the sum of edge weights).

Examples

>>> G=nx.path_graph(4)
>>> G.degree(0)
1
>>> G.degree([0,1])
[1, 2]
>>> G.degree([0,1],with_labels=True)
{0: 1, 1: 2}