• Creates a one-hot tf.Tensor. The locations represented by indices take value onValue (defaults to 1), while all other locations take value offValue (defaults to 0). If indices is rank R, the output has rank R+1 with the last axis of size depth. indices used to encode prediction class must start from 0. For example, if you have 3 classes of data, class 1 should be encoded as 0, class 2 should be 1, and class 3 should be 2.

    tf.oneHot(tf.tensor1d([0, 1], 'int32'), 3).print();
    

    Parameters

    • indices: Tensor<Rank> | TensorLike

      tf.Tensor of indices with dtype int32. Indices must start from 0.

    • depth: number

      The depth of the one hot dimension.

    • Optional onValue: number

      A number used to fill in the output when the index matches the location.

    • Optional offValue: number

      A number used to fill in the output when the index does not match the location.

    • Optional dtype: keyof DataTypeMap

      The dtype of the output tensor, default to 'int32'.

    Returns Tensor

    Doc

Generated using TypeDoc