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
I am working with python3 and networkx-2.0. The above code give the following error:
neighbors=G.neighbors_iter()
AttributeError: 'Graph' object has no attribute 'neighbors_iter'
NetworkX 2.0 makes breaking API changes. Code written for 1.x will need migration . For example, quoting the migration guide,
Methods that used to return containers now return iterators and methods that returned iterators have been removed.
neighbors_iter
isn't a thing any more; neighbors
does that job now. Similarly, predecessors_iter
and successors_iter
don't exist either.
(Also, NetworkX 2.0 isn't even out yet. You probably shouldn't be using the development branch.)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.