eelbrain.NDVar.label_clusters
- NDVar.label_clusters(threshold=0, tail=0, name=None)
Find and label clusters of values exceeding a threshold
- Parameters:
threshold (scalar) – Threshold value for clusters (default 0 to find clusters of non-zero values).
tail (0 | -1 | 1) – Whether to label cluster smaller than threshold, larger than threshold, or both (default).
name (str) – Name of the output NDVar (default is the current name).
- Returns:
clusters – NDVar of int, each cluster labeled with a unique integer value.
clusters.info['cids']
contains an array of all cluster IDs.- Return type:
Notes
Together, the labels in the
clusters
array and the identifiers inclusters.info['cids']
can be used as input forscipy.ndimage
functions. For example, count the number of elements in each label of a binarymask
:>>> from scipy import ndimage >>> labels = mask.label_clusters() >>> ns = ndimage.measurements.sum(mask, labels, labels.info['cids']) >>> dict(zip(labels.info['cids'], ns)) {1: 35.0, 6: 1.0, 37: 1.0} >>> (labels == 1).sum() # confirm count in label 1 35