one_hot

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

Return the one-hot representation for input.

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

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

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

You can also set the on_value or off_value:

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

dragon.Tensor – The output tensor.