当前位置:   article > 正文

AttributeError: module ‘networkx‘ has no attribute ‘from_numpy_matrix‘解决方法_module 'networkx' has no attribute 'info

module 'networkx' has no attribute 'info

在我学习louvain算法时,运行了这样一段代码

  1. from communities.algorithms import louvain_method
  2. from communities.visualization import draw_communities
  3. import numpy as np
  4. adj_matrix = np.array([[0, 1, 1, 0, 0, 0],
  5. [1, 0, 1, 0, 0, 0],
  6. [1, 1, 0, 1, 0, 0],
  7. [0, 0, 1, 0, 1, 1],
  8. [0, 0, 0, 1, 0, 1],
  9. [0, 0, 0, 1, 1, 0]])
  10. communities, frames = louvain_method(adj_matrix)
  11. 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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/637679
推荐阅读
相关标签
  

闽ICP备14008679号