Network.connected_components

Network.connected_components(edges=None, return_labels: bool = True)[source]

Extract connected components from network.

Parameters
edgesint or array_like, optional

If not None, get connected components for sub-network build from edges.

return_labelsbool, default=True

If True (default), return the labels for each of the connected components.

Returns
n_components: int

The number of connected components.

labels: ndarray, optional

The length-N array of labels of the connected components.

Examples

Separating Sioux-Falls:

>>> import paminco
>>> net = paminco.net.load_sioux()
>>> net.delete_nodes(["6", "9", "11", "13"], is_label=True)
(4, 24, 172)
>>> net.connected_components(return_labels=False)
2