classes_from_labels

classes_from_labels(labels: ndarray, delim: str = '-', which: int = 0, crop: slice = slice(None, None, None), cats: dict = None) tuple[dict, ndarray][source][source]

Extract class IDs from string labels.

This function processes string labels to extract class IDs using a
delimiter, and returns a dictionary mapping class names to indices and an

array of class indices.

Parameters:
  • labels (np.ndarray) – Array of string labels to process.

  • delim (str, optional) – Delimiter to split the labels, by default ‘-‘.

  • which (int, optional) – Which part of the split label to use, by default 0.

  • crop (slice, optional) – Slice to apply to each label part, by default slice(None).

  • cats (dict, optional) – Existing category mapping to use. If None, a new mapping is created.

Returns:

A tuple containing: - Dictionary mapping class names to indices - Array of class indices corresponding to the input labels

Return type:

tuple[dict, np.ndarray]

Examples

>>> labels = np.array(['cat-dog', 'dog-cat', 'cat-bird'])
>>> classes_from_labels(labels, delim='-')
({'cat': 0, 'dog': 1}, array([0, 1, 0]))

Examples using ieeg.decoding.decode.classes_from_labels

PCA-LDA Decoding

PCA-LDA Decoding