NetworkX

Previous topic

networkx.generators.line.line_graph

Next topic

networkx.generators.stochastic.stochastic_graph

networkx.generators.ego.ego_graph

ego_graph(G, n, radius=1, center=True, undirected=False)

Returns induced subgraph of neighbors centered at node n.

Parameters:

G : graph

A NetworkX Graph or DiGraph

n : node

A single node

radius : integer, optional

Include all neighbors of distance<=radius from n

center : bool, optional

If False, do not include center node in graph

undirected: bool, optional :

If True use both in- and out-neighbors of directed graphs.

Notes

For directed graphs D this produces the “out” neighborhood or successors. If you want the neighborhood of predecessors first reverse the graph with D.reverse(). If you want both directions use the keyword argument undirected=True.