maximum_spanning_tree networkx没有属性 [英] maximum_spanning_tree networkx has no attribute

查看:144
本文介绍了maximum_spanning_tree networkx没有属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用networkx python模块查找网络的最大生成树. 根据指定的文档[下面的链接],nx.maximum_spanning_tree(G)应该完成这项工作.但是我出错了

I am trying to find maximum spanning tree of a network using networkx python module. According to documentation specified[link below], nx.maximum_spanning_tree(G) should do this work. But i am getting error

  File "air_traffic_network_base.py", line 65, in <module>
    max_spanning_tree = nx.maximum_spanning_tree(net)
AttributeError: 'module' object has no attribute 'maximum_spanning_tree'

这是代码段:

net = nx.read_weighted_edgelist(graph_file)
min_spanning_tree = nx.minimum_spanning_tree(net) #no error
max_spanning_tree = nx.maximum_spanning_tree(net) #error here

文档: http://networkx.readthedocs.org /en/latest/reference/generation/networkx.algorithms.tree.mst.maximum_spanning_tree.html

Networkx version (nx.__version__):
1.10

我相信我正在使用最新的networkx python模块.(minimum_spanning_tree函数调用有效,没有任何错误).

I believe i am using latest networkx python module.(minimum_spanning_tree function call works without any error).

请帮助.

推荐答案

我相信这是由于您的网络受到了指挥.在这种情况下,maximum_spanning_tree将不起作用.由于作为文档报告,因此只能在无向图上完成.

I believe this is due to your net being directed. If that is the case, maximum_spanning_tree will not work. Since as the documentation reports, it can only be done on an undirected graph.

可以用两者表示的模型是等效的,因此这只是对用因子表示模型的方式的一种更改.要从无向树制作有向树,只需选择任何节点作为根,然后将边缘定向远离根即可.

The models that can be represented by the two are equivalent, and so it's just a change to the way you represent the model with factors. To make a directed tree from an undirected one, just pick any node as the root and orient the edges away from the root.

这篇关于maximum_spanning_tree networkx没有属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆