one_hot_encoding_vec

Function one_hot_encoding_vec 

Source
pub fn one_hot_encoding_vec<T: AsRef<[usize]>>(
    input_array: T,
) -> Result<Array2<f64>, Box<dyn Error>>
Expand description

Generates a one-hot encoding for a vector of integers.

§Arguments

  • input_array: List of integers to be encoded. Each integer should be less than or equal to the maximum integer in the array.

Returns: Array2<f64> where each row represents the one-hot encoding of the corresponding integer from the input array. The columns represent the range of integers from the input array.

§Errors

Returns an error if the input_array is empty.

§Examples

use ducky_learn::util::one_hot_encoding_vec;
use ndarray::prelude::*;

let input_array = vec![2, 0, 1];
let output_array = array![
    [0., 0., 1.],
    [1., 0., 0.],
    [0., 1., 0.]
];

assert_eq!(one_hot_encoding_vec(input_array).unwrap(), output_array);