eelbrain.Factor.update_labels

Factor.update_labels(labels)

Change one or more labels in place

Parameters:

labels (dict) – Mapping from old labels to new labels. Existing labels that are not in labels are kept.

Examples

>>> f = Factor('aaabbbccc')
>>> f
Factor(['a', 'a', 'a', 'b', 'b', 'b', 'c', 'c', 'c'])
>>> f.update_labels({'a': 'v1', 'b': 'v2'})
>>> f
Factor(['v1', 'v1', 'v1', 'v2', 'v2', 'v2', 'c', 'c', 'c'])

In order to create a copy of the Factor with different labels just use the labels argument when initializing a new Factor:

>>> Factor(f, labels={'c': 'v3'})
Factor(['v1', 'v1', 'v1', 'v2', 'v2', 'v2', 'v3', 'v3', 'v3'])