jax-js
    Preparing search index...

    Function oneHot

    • One-hot encodes the given indices.

      Each index in the integer input x is encoded as a vector of zeros of length numClasses, with a 1 at the index position specified by its value.

      import { nn, numpy as np } from '@jax-js/jax';

      nn.oneHot(np.array([1, 1, 2], { dtype: np.int32 }), 3);
      // Output:
      // [[0, 1, 0],
      // [0, 1, 0],
      // [0, 0, 1]]

      Parameters

      • x: Array
      • numClasses: number

      Returns Array