赞
踩
在我学习louvain算法时,运行了这样一段代码
- from communities.algorithms import louvain_method
- from communities.visualization import draw_communities
- import numpy as np
- adj_matrix = np.array([[0, 1, 1, 0, 0, 0],
- [1, 0, 1, 0, 0, 0],
- [1, 1, 0, 1, 0, 0],
- [0, 0, 1, 0, 1, 1],
- [0, 0, 0, 1, 0, 1],
- [0, 0, 0, 1, 1, 0]])
-
- communities, frames = louvain_method(adj_matrix)
- draw_communities(adj_matrix, communities)
运行报错
AttributeError: module 'networkx' has no attribute 'from_numpy_matrix'
问题原因及解决方案:
在 .networkx 3.0 中,变更日志显示以下内容“删to_numpy_matrix
& from_numpy_matrix
(#5746)” https:/.networkx.org/documentation/stable/release/release_3.0.html您必须降级.networkx 或改用G=nx.from_numpy_array(A)
。 https:/.networkx.org/documentation/stable/reference/readwrite/matrix_market.html
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。