to1hot

ketos.data_handling.data_handling.to1hot(value, depth)[source]

Converts the binary label to one hot format

Args:
value: scalar or numpy.array | int or float

The the label to be converted.

depth: int

The number of possible values for the labels (number of categories).

Returns:
one_hot:numpy array (dtype=float64)

A len(value) by depth array containg the one hot encoding for the given value(s).

Example:
>>> from ketos.data_handling.data_handling import to1hot
>>>
>>> # An example with two possible labels (0 or 1)
>>> values = np.array([0,1])
>>> to1hot(values,depth=2)
array([[1., 0.],
       [0., 1.]])
>>>
>>> # The same example with 4 possible labels (0,1,2 or 3)
>>> values = np.array([0,1])
>>> to1hot(values,depth=4)
array([[1., 0., 0., 0.],
       [0., 1., 0., 0.]])