python - 模块“networkx”没有属性“stochastic_block_model”
问题描述
我正在尝试使用此页面中记录的networkx“stochastic_block_model”中的函数生成随机块模型图:https ://networkx.github.io/documentation/stable/reference/generated/networkx.generators.community.stochastic_block_model.html
我的 networkx 包已更新到 2.2 版本,但我不断收到错误消息:模块“networkx”没有属性“stochastic_block_model”。我该如何解决这个问题?
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))
解决方案
关键是我必须在升级包后终止正在运行的实例并重新启动我的笔记本或任何 python shell 以获得新的更新。
推荐阅读
- c# - 将数据表导出到多语言内容的 Excel
- c++ - LibHaru 库出现问题
- snowflake-cloud-data-platform - Snowflake 过程中 While 循环中的 IF 条件
- microsoft-forms - 我如何知道是否有人回答了排序顺序 MS Forms 问题或只是保留了默认顺序?
- javascript - 滚动到部分时更改 URL
- android - ImageView 适合有限空间并保持相同的缩小比例
- arrays - 比较 A 和 B 列表并创建一个 C 列表,其中 B 值不在 Powershell 的 A 列表中
- python - 关于如何在 Python 中创建 CrossTab 的困惑
- c# - StarSchema - 实体框架核心 - 迁移
- r - 计算人口年龄四分位数范围并将结果存储为 R 中的数据框的最佳方法