seg1d.Segmenter.add_reference¶
-
Segmenter.
add_reference
(r, copy=True)[source]¶ Appends a reference containing one or more features to the existing reference dataset. If the reference is not a dict, it will be converted to one. If this should be the only reference set, use
clear_reference()
before calling this method.Parameters: - rdict or ndarray
- Dictionary containing labeled features as keys and values as 1-D arrays (must be same size).ndarray of dimension 1 will be used as a single feature for the reference.ndarray of n-dimensions will use rows as unique features.
- copybool, optional
If True, will make a deepcopy of the passed parameter (Default True).
See also
set_target
- Set the target data
clear_reference
- Clear the current reference data
Notes
This method allows features that are not in previous references to be added, and vice-versa. It will also allow different sizes of reference data to be added. This is done as you can explicitly declare which features to use when segmenting.
Examples
Add a reference with multiple features
>>> import seg1d >>> import numpy as np >>> >>> s = seg1d.Segmenter() >>> r = np.linspace(0,1,6).reshape(2,3) >>> s.add_reference( r ) >>> s.r [{'0': array([0. , 0.2, 0.4]), '1': array([0.6, 0.8, 1. ])}]
Alternatively, each row of the array can be added as the same labeled feature for different references by calling this method in a loop. Notice this is now an array of dictionaries containing the same feature label.
>>> s = seg1d.Segmenter() >>> r = np.linspace(0,1,6).reshape(2,3) >>> for _r in r: s.add_reference(_r) >>> s.r [{'0': array([0. , 0.2, 0.4])}, {'0': array([0.6, 0.8, 1. ])}]