本文整理汇总了Python中networkx.Graph.remove_nodes_from方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.remove_nodes_from方法的具体用法?Python Graph.remove_nodes_from怎么用?Python Graph.remove_nodes_from使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类networkx.Graph
的用法示例。
在下文中一共展示了Graph.remove_nodes_from方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: print
# 需要导入模块: from networkx import Graph [as 别名]
# 或者: from networkx.Graph import remove_nodes_from [as 别名]
print('{0}/{1} nodes processed'.format(i, n), end='\r')
print('{0}/{1} nodes processed'.format(i, n))
print('Search for orphaned nodes')
orphaned = set()
n = graph.number_of_nodes()
i = 0
for node in graph.nodes_iter():
if graph.degree(node) == 0:
orphaned.add(node)
i += 1
print('{0}/{1} nodes processed'.format(i, n), end='\r')
print('{0}/{1} nodes processed'.format(i, n))
print('Delete {0} orphaned nodes'.format(len(orphaned)))
graph.remove_nodes_from(orphaned)
print('Calculate offset')
points = [node[1]['pos'] for node in graph.nodes(data=True)]
min_x = min(points, key=lambda p: p[0])[0]
min_y = min(points, key=lambda p: p[1])[1]
for node in graph.nodes_iter():
pos = (graph.node[node]['pos'][0] - min_x, graph.node[node]['pos'][1] - min_y)
graph.node[node]['pos'] = pos
print('Translated data by ({0}, {1})'.format(-min_x, -min_y))
print('Calculate edge weights')
n = graph.number_of_edges()
i = 0
for edge in graph.edges():
lat1 = math.radians(graph.node[edge[0]]['lat'])