在我学习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'
问题原因及解决方案:文章来源:https://www.toymoban.com/news/detail-507126.html
在 .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文章来源地址https://www.toymoban.com/news/detail-507126.html
到了这里,关于AttributeError: module ‘networkx‘ has no attribute ‘from_numpy_matrix‘解决方法的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!