【问题标题】:NetworkX.rich_club_coefficient() throwing numpy.AxisError: axis -1 is out of bounds for array of dimension 0NetworkX.rich_club_coefficient() throwing numpy.AxisError: axis -1 is out of bounds for array of dimension 0
【发布时间】:2020-05-18 15:56:50
【问题描述】:

我很难理解我能做些什么,或者它甚至意味着什么。

这是我的代码:

g = nx.read_gml(testfile)
rc = nx.rich_club_coefficient(g)

然后,我收到错误:

numpy.AxisError: axis -1 is out of bounds for array of dimension 0

我不确定我的图表中的原因是什么。我希望有人对nx.rich_club_coefficient 有过经验,或许能对这种困境有所启发。谢谢!

【问题讨论】:

  • 你能在g = ...之后打印g.edgesg.nodes的值吗?您也可以注释掉rc = ... 行,以准确找出引发此错误的行。
  • 感谢您的评论! g.nodesg.edges 会有点难。这是nx.info(g)Name: Type: Graph Number of nodes: 4414 Number of edges: 210538 Average degree: 95.3956 另外,感谢您提供关于注释掉rc 的提示!
  • 你能用行号等复制完整的 Traceback 错误吗?
  • 我想通了。是我网络中的隔离物与nx.rich_club_cofficient 不一致。我添加了这一行,graph.remove_nodes_from(list(nx.isolates(graph))),它现在工作得很好。感谢您发表评论并尝试提供帮助。这就是让这个网站如此神奇的原因。我一定会记住那个查看线路错误的技巧!

标签: python-3.x numpy networkx


【解决方案1】:

看来我已经明白了。

由于某种原因,网络中的隔离物无法很好地使用该功能。

我添加了graph.remove_nodes_from(list(nx.isolates(graph))),它工作正常。

我希望这对其他人也有帮助。

【讨论】:

    猜你喜欢
    • 2017-04-09
    • 2021-12-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-20
    • 1970-01-01
    • 2019-09-21
    • 2020-03-13
    相关资源
    最近更新 更多