(i, depth, axis=-1)
return x
Convert integer categorical indices to one-hot probability vectors.

  Args:
    i: an array of integer categorical indices.
    depth: the number of categories.
    axis: the axis on which to lay out the categories.

  Returns:
    An array of one-hot categorical indices, shaped like `i` but with a
    categorical axis in the location specified by `axis`.
Convert integer categorical indices to one-hot probability vectors.
Convert integer categorical indices to one - hot probability vectors .
def to_onehot(i, depth, axis=-1):
  """Convert integer categorical indices to one-hot probability vectors.

  Args:
    i: an array of integer categorical indices.
    depth: the number of categories.
    axis: the axis on which to lay out the categories.

  Returns:
    An array of one-hot categorical indices, shaped like `i` but with a
    categorical axis in the location specified by `axis`.
  """
  x = np.eye(depth)[i]
  axis %= x.ndim
  if axis != x.ndim - 1:
    # move new axis forward
    axes = list(range(x.ndim - 1))
    axes.insert(axis, x.ndim - 1)
    x = np.transpose(x, axes)
  assert np.allclose(x.sum(axis=axis), 1)
  return x
def to_onehot ( i , depth , axis = - 1 ) : x = np . eye ( depth ) [ i ] axis %= x . ndim if axis != x . ndim - 1 : # move new axis forward axes = list ( range ( x . ndim - 1 ) ) axes . insert ( axis , x . ndim - 1 ) x = np . transpose ( x , axes ) assert np . allclose ( x . sum ( axis = axis ) , 1 ) return x