def ego_graph(G, n, radius=1, center=True, undirected=False, distance=None):
 if undirected:
  if (distance is not None):
   (sp, _) = nx.single_source_dijkstra(G.to_undirected(), n, cutoff=radius, weight=distance)
  else:
   sp = dict(nx.single_source_shortest_path_length(G.to_undirected(), n, cutoff=radius))
 elif (distance is not None):
  (sp, _) = nx.single_source_dijkstra(G, n, cutoff=radius, weight=distance)
 else:
  sp = dict(nx.single_source_shortest_path_length(G, n, cutoff=radius))
 H = G.subgraph(sp).copy()
 if (not center):
  H.remove_node(n)
 return H

def ego_graph ( G , n , radius = 1 , center = True , undirected = False , distance = None ) : if undirected : if ( distance is not None ) : ( sp , _ ) = nx . single_source_dijkstra ( G . to_undirected ( ) , n , cutoff = radius , weight = distance ) else : sp = dict ( nx . single_source_shortest_path_length ( G . to_undirected ( ) , n , cutoff = radius ) ) elif ( distance is not None ) : ( sp , _ ) = nx . single_source_dijkstra ( G , n , cutoff = radius , weight = distance ) else : sp = dict ( nx . single_source_shortest_path_length ( G , n , cutoff = radius ) ) H = G . subgraph ( sp ) . copy ( ) if ( not center ) : H . remove_node ( n ) return H
returns induced subgraph of neighbors centered at node n within a given radius .