[英]'Graph' object has no attribute 'nodes_iter' in networkx module python
[英]module 'networkx' has no attribute 'add_nodes_from'
我有一本字典,作者名字符串作為索引,出版物數量作為關聯值。 當我嘗試從中將節點添加到新圖時,出現以下錯誤:
AttributeError: module 'networkx' has no attribute 'add_nodes_from'
這是一個示例代碼:
import networkx as nx
auth_dict = {"albert": 1, "Barbie": 3, "Charlie": 8}
G = nx.MultiGraph()
G = nx.add_nodes_from(auth_dict)
環境是由pip管理的python 3.7.2和networkx 2.2,MacOS 10.13.6
這是我嘗試遵循的參考: https : //networkx.github.io/documentation/stable/reference/classes/generation/networkx.Graph.add_nodes_from.html#networkx.Graph.add_nodes_from
謝謝
您從錯誤的方式調用add_nodes_from
。 它是MultiGraph
基類的方法,而不是networkx
模塊本身的屬性。 所以語法應該是
G = nx.MultiGraph()
G.add_nodes_from(auth_dict)
(注意點而不是'=')。
所以我想你把它稱為
G = nx.add_nodes_from(foo)
在您的主代碼中,這又是錯誤的語法-請查看此處或您自己發布的鏈接以獲取更多信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.