braintools.cogtask.one_hot

Contents

braintools.cogtask.one_hot#

braintools.cogtask.one_hot(key, num_classes=None, active_value=1.0)[source]#

Create a one-hot encoding value specification.

Parameters:
  • key (str) – Context key containing the class index.

  • num_classes (int | None) – Number of classes. If None, inferred from feature.num.

  • active_value (float) – Value for the active class (default 1.0).

Returns:

Encoder function (ctx, feature) -> np.ndarray

Return type:

Callable[[Context, Feature], Array]

Examples

>>> inputs={'stimulus': one_hot('sample_idx')}
>>> inputs={'stimulus': one_hot('sample_idx', num_classes=8)}