utils.reindex_cluster_labels

utils.reindex_cluster_labels(labels)

Re-index integer cluster labels to be consecutive non-negative integers. This is useful because the LevelSetTree.get_clusters method returns cluster labels that match level set tree node indices. These are generally not consecutive whole numbers.

Parameters:

labels : numpy.array

Cluster labels returned from the LevelSetTree.get_clusters method. The first column should be row indices and the second column should be integers corresponding to ID numbers of nodes in the level set tree.

Returns:

new_labels : numpy.array

Cluster labels in the same form of the input ‘labels’, but with cluster labels re-indexed to be consecutive non-negative integers.

See also

LevelSetTree.get_clusters

Examples

>>> X = numpy.random.rand(100, 2)
>>> tree = debacl.construct_tree(X, k=8, prune_threshold=5)
>>> labels = tree.get_clusters(method='leaf')
>>> numpy.unique(labels[:, 1])
array([1, 5, 6])
...
>>> new_labels = debacl.utils.reindex_cluster_labels(labels)
>>> numpy.unique(new_labels[:, 1])
array([0, 1, 2])