easygraph.functions package

Subpackages

Submodules

easygraph.functions.isolate module

Functions for identifying isolate (degree zero) nodes.

easygraph.functions.isolate.is_isolate(G, n)[source]

Determines whether a node is an isolate.

An isolate is a node with no neighbors (that is, with degree zero). For directed graphs, this means no in-neighbors and no out-neighbors.

Parameters:
  • G (EasyGraph graph) –

  • n (node) – A node in G.

Returns:

is_isolate – True if and only if n has no neighbors.

Return type:

bool

Examples

>>> G = eg.Graph()
>>> G.add_edge(1, 2)
>>> G.add_node(3)
>>> eg.is_isolate(G, 2)
False
>>> eg.is_isolate(G, 3)
True
easygraph.functions.isolate.isolates(G)[source]

Iterator over isolates in the graph.

An isolate is a node with no neighbors (that is, with degree zero). For directed graphs, this means no in-neighbors and no out-neighbors.

Parameters:

G (EasyGraph graph) –

Returns:

An iterator over the isolates of G.

Return type:

iterator

Examples

To get a list of all isolates of a graph, use the list constructor:

>>> G = eg.Graph()
>>> G.add_edge(1, 2)
>>> G.add_node(3)
>>> list(eg.isolates(G))
[3]

To remove all isolates in the graph, first create a list of the isolates, then use Graph.remove_nodes_from():

>>> G.remove_nodes_from(list(eg.isolates(G)))
>>> list(G)
[1, 2]

For digraphs, isolates have zero in-degree and zero out_degre:

>>> G = eg.DiGraph([(0, 1), (1, 2)])
>>> G.add_node(3)
>>> list(eg.isolates(G))
[3]
easygraph.functions.isolate.number_of_isolates(G)[source]

Returns the number of isolates in the graph.

An isolate is a node with no neighbors (that is, with degree zero). For directed graphs, this means no in-neighbors and no out-neighbors.

Parameters:

G (EasyGraph graph) –

Returns:

The number of degree zero nodes in the graph G.

Return type:

int

Module contents