Skip to content

Connected Components

Get the connected components for this neuron.

PARAMETER DESCRIPTION
node_ids
     Array of node IDs.

TYPE: (N, ) array

parent_ids
     Array of parent IDs for each node. Root nodes' parents
     must be -1.

TYPE: (N, ) array

RETURNS DESCRIPTION
cc

For each node the node ID of its root (= connected component ID).

TYPE: (N, ) int32 array

Examples:

Fully connected neuron:

>>> import navis_fastcore as fastcore
>>> import numpy as np
>>> node_ids = np.arange(7)
>>> parent_ids = np.array([-1, 0, 1, 2, 1, 4, 5])
>>> fastcore.connected_components(node_ids, parent_ids)
array([0, 0, 0, 0, 0, 0, 0])

Introduce a break:

>>> parent_ids[4] = -1
>>> fastcore.connected_components(node_ids, parent_ids)
array([0, 0, 0, 0, 4, 4, 4])