I write this code to generate scale free network with power law degree distribution.
import networkx as nx
import random
N = 1000
exponent = 2.2
test = [int(random.paretovariate(exponent-1)) for i in range(N)]
graph = nx.configuration_model(test)
print("number of self-loops : ", graph.number_of_selfloops())
but I face this error:
AttributeError: 'MultiGraph' object has no attribute 'number_of_selfloops'
I can't understand what is the problem and how can I fix it. Is there any other ways to generate such network with networkX? (I don't want self-loops and multi-links to be removed)
As stated in the documentation of configuration_model
this function returns a MultiGraph
, which does not have the method number_of_selfloops
, but you can still use the nx.number_of_selfloops
method, which also works for MultiGraph
(NetworkX changed how they want to have the call for such methods) or simply create a usual graph with non_multi_graph = nx.Graph(graph)
.