Alexandra Bradan
Alexandra Bradan

Reputation: 185

Why do I get AttributeError: module 'networkx' has no attribute 'average_neighbor_in_degree'?

I have networkx v.2.3 and I need to compute the average neighbor degree of the nodes of a directed graph. Why is the method is not being recognized?

import networkx as nx

G = nx.DiGraph()
G.add_path([0,1,2,3])
nx.average_neighbor_in_degree(G)

Upvotes: 3

Views: 3153

Answers (1)

CDJB
CDJB

Reputation: 14516

The average_neighbor_in_degree method was replaced in networkx 1.6 - see release notes (thanks @Delena Malan).

This functionality is available in networkx 2.3 with the average_neighbor_degree method using the target & source keyword arguments:

Code:

import networkx as nx

G = nx.DiGraph()
G.add_path([0,1,2,3])
print(nx.average_neighbor_degree(G, source='in', target='in'))

Output:

{0: 1.0, 1: 1.0, 2: 1.0, 3: 0.0}

Upvotes: 3

Related Questions