one_hot

dragon.one_hot(
  inputs,
  depth,
  on_value=1,
  off_value=0,
  **kwargs
)[source]

Return the one-hot representation of input.

\[\text{out}_{ij} = \begin{cases} \text{off\_value}, & \text{ if } \text{input}_{i} \neq j \\ \text{on\_value}, & \text{ otherwise } \end{cases} \]

The max value of input, i.e., the depth should be specified:

x = dragon.constant([0, 1, 2, 3])
print(dragon.one_hot(x, depth=5))  # depth >= 4 will be ok

Use on_value or off_value custom filling:

x = dragon.constant([0, 1, 2, 3])
print(dragon.one_hot(x, depth=4, on_value=2, off_value=3))
Parameters:
  • inputs (dragon.Tensor) The input tensor.
  • depth (int) The depth of representation.
  • on_value (number, optional, default=1) The value for equal branch.
  • off_value (number, optional, default=0) The value for not-equal branch.
Returns:

dragon.Tensor The output tensor.