tensor.onehot
fn onehot(self: @Tensor<T>, depth: usize, axis: Option<usize>, values: Span<usize>) -> Tensor<usize>;Produces one-hot tensor based on input.
Args
self(@Tensor<T>) - The input tensor.depth(usize) - Scalar or Rank 1 tensor containing exactly one element, specifying the number of classes in one-hot tensor.axis(Option<bool>) - Axis along which one-hot representation in added. Default: axis=-1.values(Span<usize>) - Rank 1 tensor containing exactly two elements, in the format [off_value, on_value]
Panics
Panics if values is not equal to 2.
Returns
A new Tensor<T> one-hot encode of the input tensor.
Type Constraints
Constrain input and output types to fixed point tensors.
Example
Last updated
Was this helpful?