0

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)

Atefeh Rashidi
  • 485
  • 1
  • 8
  • 32

1 Answers1

1

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).

Sparky05
  • 4,692
  • 1
  • 10
  • 27
  • I want to have MultiGraph. I don't want to remove multi-links and self-loops. This code : non_multi_graph = nx.Graph(graph) return Graph and also I get this error again : 'Graph' object has no attribute 'number_of_selfloops' @Sparky05 – Atefeh Rashidi Apr 11 '20 at 08:34