networkx 2.8.2 Pypi GitHub Homepage
Other Docs
ParametersRaisesReturnsBackRef
average_neighbor_degree(G, source='out', target='out', nodes=None, weight=None)

In an undirected graph, the neighborhood :None:None:`N(i)` of node i contains the nodes that are connected to i by an edge.

For directed graphs, :None:None:`N(i)` is defined according to the parameter :None:None:`source`:

The average neighborhood degree of a node i is

$$k_{nn,i} = \frac{1}{|N(i)|} \sum_{j \in N(i)} k_j$$

where :None:None:`N(i)` are the neighbors of node i and :None:None:`k_j` is the degree of node :None:None:`j` which belongs to :None:None:`N(i)`. For weighted graphs, an analogous measure can be defined ,

$$k_{nn,i}^{w} = \frac{1}{s_i} \sum_{j \in N(i)} w_{ij} k_j$$

where :None:None:`s_i` is the weighted degree of node i, :None:None:`w_{ij}` is the weight of the edge that links i and :None:None:`j` and :None:None:`N(i)` are the neighbors of node i.

Parameters

G : NetworkX graph
source : string ("in"|"out"|"in+out"), optional (default="out")

Directed graphs only. Use "in"- or "out"-neighbors of source node.

target : string ("in"|"out"|"in+out"), optional (default="out")

Directed graphs only. Use "in"- or "out"-degree for target node.

nodes : list or iterable, optional (default=G.nodes)

Compute neighbor degree only for specified nodes.

weight : string or None, optional (default=None)

The edge attribute that holds the numerical value used as a weight. If None, then each edge has weight 1.

Raises

NetworkXError

If either :None:None:`source` or :None:None:`target` are not one of 'in', 'out', or 'in+out'. If either :None:None:`source` or :None:None:`target` is passed for an undirected graph.

Returns

d: dict

A dictionary keyed by node to the average degree of its neighbors.

Returns the average degree of the neighborhood of each node.

See Also

average_degree_connectivity

Examples

>>> G = nx.path_graph(4)
... G.edges[0, 1]["weight"] = 5
... G.edges[2, 3]["weight"] = 3
>>> nx.average_neighbor_degree(G)
{0: 2.0, 1: 1.5, 2: 1.5, 3: 2.0}
>>> nx.average_neighbor_degree(G, weight="weight")
{0: 2.0, 1: 1.1666666666666667, 2: 1.25, 3: 2.0}
>>> G = nx.DiGraph()
... nx.add_path(G, [0, 1, 2, 3])
... nx.average_neighbor_degree(G, source="in", target="in") {0: 0.0, 1: 0.0, 2: 1.0, 3: 1.0}
>>> nx.average_neighbor_degree(G, source="out", target="out")
{0: 1.0, 1: 1.0, 2: 0.0, 3: 0.0}
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

networkx.algorithms.assortativity.connectivity.average_degree_connectivity networkx.algorithms.assortativity.neighbor_degree.average_neighbor_degree

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /networkx/algorithms/assortativity/neighbor_degree.py#6
type: <class 'function'>
Commit: