正在尝试使用源用户\u id和目标用户\u id访问边缘
# so we can access the edge using the source user_id and the target user_id
G.edges([nodelist[0]][list(e.keys())[0]])
错误:
AttributeError Traceback (most recent call last)
<ipython-input-48-12593dd17b79> in <module>
1 # so we can access the edge using the source user_id and the target user_id
----> 2 G.edges([nodelist[0]][list(e.keys())[0]])
AttributeError: 'OutEdgeDataView' object has no attribute 'keys'
我面临的另一个错误…
正在尝试列出所有节点
# listing all nodes
nodelist = G.nodes()
nodelist[:3]
错误:
TypeError Traceback (most recent call last)
<ipython-input-56-0135a95aa2ab> in <module>
1 # listing all nodes
2 nodelist = G.nodes()
----> 3 nodelist[:3]
~\anaconda3\lib\site-packages\networkx\classes\reportviews.py in __getitem__(self, n)
176
177 def __getitem__(self, n):
--> 178 return self._nodes[n]
179
180 # Set methods
TypeError: unhashable type: 'slice'
我相信你的错误是相关的。我不确定,因为您没有在上面的代码中定义变量
e
,但是根据错误中的类型,您似乎将其定义为e = G.edges()
,它返回一个OutEdgeDataView
对象,而不是您想要的dict。您可以使用e = list(G.edges())
获得图形边的列表,该列表提供元组列表,其中元组的第一项是源节点,第二项是目标节点。然后,要获取与nodelist[0]
对应的边的边属性,可以说G.edge[nodelist[0],the_tail_node]
对于第二个错误,G.nodes()不是列表,不支持切片。当您在上面定义
nodelist
时,您可以执行nodelist = list(G.nodes())
,然后可以根据需要进行切片相关问题 更多 >
编程相关推荐