MCPcopy Create free account
hub / github.com/easy-graph/Easy-Graph / ego_subgraph

Method ego_subgraph

easygraph/classes/directed_graph.py:1112–1138  ·  view source on GitHub ↗

Returns an ego network graph of a node. Parameters ---------- center : object The center node of the ego network graph Returns ------- ego_subgraph : easygraph.Graph The ego network graph of *center*. Examples

(self, center)

Source from the content-addressed store, hash-verified

1110 return G
1111
1112 def ego_subgraph(self, center):
1113 """Returns an ego network graph of a node.
1114
1115 Parameters
1116 ----------
1117 center : object
1118 The center node of the ego network graph
1119
1120 Returns
1121 -------
1122 ego_subgraph : easygraph.Graph
1123 The ego network graph of *center*.
1124
1125
1126 Examples
1127 --------
1128 >>> G = eg.Graph()
1129 >>> G.add_edges([
1130 ... ('Jack', 'Maria'),
1131 ... ('Maria', 'Andy'),
1132 ... ('Jack', 'Tom')
1133 ... ])
1134 >>> G.ego_subgraph(center='Jack')
1135 """
1136 neighbors_of_center = list(self.all_neighbors(center))
1137 neighbors_of_center.append(center)
1138 return self.nodes_subgraph(from_nodes=neighbors_of_center)
1139
1140 def to_index_node_graph(self, begin_index=0):
1141 """Returns a deep copy of graph, with each node switched to its index.

Callers

nothing calls this directly

Calls 3

all_neighborsMethod · 0.95
nodes_subgraphMethod · 0.95
appendMethod · 0.80

Tested by

no test coverage detected