changepoints_to_labels#
- changepoints_to_labels(changepoints: ndarray, n_samples: int, labels: ndarray | None = None) ndarray[source][source]#
Convert changepoint indices to per-sample segment labels.
- Parameters:
- changepointsnp.ndarray
Changepoint indices, shape (n_changepoints,).
- n_samplesint
Number of samples in the time series.
- labelsnp.ndarray | None, default=None
Segment labels, shape (n_changepoints + 1,). If None, auto-generates [0, 1, 2, …].
- Returns:
- np.ndarray
Segment labels, shape (n_samples,). Each sample assigned its segment label.
Examples
>>> changepoints = np.array([50, 100]) >>> labels = changepoints_to_labels(changepoints, n_samples=150) >>> labels.shape (150,) >>> np.unique(labels) array([0, 1, 2])