我试图使用networkx "stochastic_block_model“中的函数生成随机块模型图,该页面记录在以下页面:model.html
我的networkx包被更新为2.2版本,但我一直收到错误:模块'networkx‘没有属性’随机_块_模型‘。我怎么能解决这个问题?
import networkx as nx
sizes = [75, 75, 300]
probs = [[0.25, 0.05, 0.02],
[0.05, 0.35, 0.07],
[0.02, 0.07, 0.40]]
g = nx.stochastic_block_model(sizes, probs, seed=0)
len(g)
H = nx.quotient_graph(g, g.graph['partition'], relabel=True)
for v in H.nodes(data=True):
print(round(v[1]['density'], 3))
for v in H.edges(data=True):
print(round(1.0 * v[2]['weight'] / (sizes[v[0]] * sizes[v[1]]), 3))发布于 2018-10-29 19:45:58
关键是,在升级包之后,我必须关闭正在运行的实例,重新启动我的笔记本或其他python,以获得新的更新。
发布于 2018-10-29 16:56:33
我正在使用networkx的2.2版本,这是pypi上的最新版本。这应该是可行的:
from networkx.generators.community import stochastic_block_model
在生成器的__init__.py networkx.generators包中,您会发现以下内容:
"""
A package for generating various graphs in networkx.
"""
from networkx.generators.atlas import *
from networkx.generators.classic import *
from networkx.generators.community import *
from networkx.generators.degree_seq import *
from networkx.generators.directed import *
from networkx.generators.duplication import *
from networkx.generators.ego import *
from networkx.generators.expanders import *
from networkx.generators.geometric import *
from networkx.generators.intersection import *
from networkx.generators.joint_degree_seq import *
from networkx.generators.lattice import *
from networkx.generators.line import *
from networkx.generators.mycielski import *
from networkx.generators.nonisomorphic_trees import *
from networkx.generators.random_clustered import *
from networkx.generators.random_graphs import *
from networkx.generators.small import *
from networkx.generators.social import *
from networkx.generators.spectral_graph_forge import *
from networkx.generators.stochastic import *
from networkx.generators.trees import *
from networkx.generators.triads import *因此,您应该能够像这样导入它:
from networkx.generators import stochastic_block_model
https://stackoverflow.com/questions/53049796
复制相似问题