Factor.update_labels(self, labels)

Change one or more labels in place

labels : dict

Mapping from old labels to new labels. Existing labels that are not in labels are kept.


If labels contains a key that is not a label of the Factor, a KeyError is raised.


>>> 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'])