【问题标题】:generate scale free network with power-law degree distribution by python通过python生成具有幂律度分布的无标度网络
【发布时间】:2020-04-09 22:45:49
【问题描述】:

我编写此代码来生成具有幂律度分布的无标度网络。

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

但我遇到了这个错误:

AttributeError: 'MultiGraph' 对象没有属性 'number_of_selfloops'

我不明白是什么问题以及如何解决它。 有没有其他方法可以用networkX生成这样的网络? (我不希望删除自循环和多链接)

【问题讨论】:

    标签: python networkx power-law


    【解决方案1】:

    正如configuration_model 的文档中所述,此函数返回一个MultiGraph,它没有number_of_selfloops 方法,但您仍然可以使用nx.number_of_selfloops 方法,该方法也适用于MultiGraph(NetworkX更改了他们希望调用此类方法的方式)或简单地使用non_multi_graph = nx.Graph(graph) 创建一个常用图表。

    【讨论】:

    • 我想要 MultiGraph。我不想删除多链接和自循环。此代码:non_multi_graph = nx.Graph(graph) return Graph,我再次收到此错误:'Graph' object has no attribute 'number_of_selfloops' @Sparky05
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-15
    • 1970-01-01
    • 2014-03-14
    • 1970-01-01
    • 2023-04-04
    • 1970-01-01
    相关资源
    最近更新 更多