(
        values: Union[np.ndarray, List], dtype: Type = float, dim: int = None
)
return np.eye(dim, dtype=dtype)[np.asanyarray(values, dtype=int)]
Return a one-hot transform of values

    Parameters
    ----------
    values : 1d array
        Integer values (hopefully 0-max).
    dtype
        dtype of result array
    dim
        Number of columns (attributes) in the one hot encoding. This parameter
        is used when we need fixed number of columns and values does not
        reflect that number correctly, e.g. not all values from the discrete
        variable are present in values parameter.

    Returns
    -------
    result
        2d array with ones in respective indicator columns.
Return a one-hot transform of values
Return a one - hot transform of values
def one_hot(
        values: Union[np.ndarray, List], dtype: Type = float, dim: int = None
) -> np.ndarray:
    """Return a one-hot transform of values

    Parameters
    ----------
    values : 1d array
        Integer values (hopefully 0-max).
    dtype
        dtype of result array
    dim
        Number of columns (attributes) in the one hot encoding. This parameter
        is used when we need fixed number of columns and values does not
        reflect that number correctly, e.g. not all values from the discrete
        variable are present in values parameter.

    Returns
    -------
    result
        2d array with ones in respective indicator columns.
    """
    dim_values = int(np.max(values) + 1 if len(values) > 0 else 0)
    if dim is None:
        dim = dim_values
    elif dim < dim_values:
        raise ValueError("dim must be greater than max(values)")
    return np.eye(dim, dtype=dtype)[np.asanyarray(values, dtype=int)]
def one_hot ( values : Union [ np . ndarray , List ] , dtype : Type = float , dim : int = None ) -> np . ndarray : dim_values = int ( np . max ( values ) + 1 if len ( values ) > 0 else 0 ) if dim is None : dim = dim_values elif dim < dim_values : raise ValueError ( "dim must be greater than max(values)" ) return np . eye ( dim , dtype = dtype ) [ np . asanyarray ( values , dtype = int ) ]