小编Sha*_*han的帖子

邻居=G.neighbors_iter AttributeError: 'Graph' 对象没有属性 'neighbors_iter'

import networkx as nx 
def core_number(G):
    nodes=list(G.nodes())
    if G.is_multigraph():
        raise nx.NetworkXError('MultiGraph and MultiDiGraph types not supported.')

    if G.number_of_selfloops()>0:
        raise nx.NetworkXError('Input graph has self loops; the core number is not defined.','Consider using G.remove_edges_from(G.selfloop_edges()).')

    if G.is_directed():
        def neighbors(v):
            return itertools.chain.from_iterable([G.predecessors_iter(v), G.successors_iter(v)])
    else:
        neighbors=G.neighbors_iter
    return neighbors
Run Code Online (Sandbox Code Playgroud)

我正在使用 python3 和 networkx-2.0。上面的代码给出了以下错误:

   neighbors=G.neighbors_iter()
   AttributeError: 'Graph' object has no attribute 'neighbors_iter'
Run Code Online (Sandbox Code Playgroud)

python networkx

1
推荐指数
1
解决办法
2418
查看次数

标签 统计

networkx ×1

python ×1