I have an vector of integers y <- c(1, 2, 3, 3)
and now I want to convert it into an list like this (one hot encoded):
1 0 0
0 1 0
0 0 1
0 0 1
I tried to find a solution with to_categorical but I had problems with data types... Do anyone know a smart and smooth solution for this task?
This is my try:
for (i in 1:length(y)) {
one_character <- list(as.vector(to_categorical(y[[i]], num_classes = 3)))
list_test <- rbind(list_test, one_character)
}
but I get the following error:
Error in py_call_impl(callable, dots$args, dots$keywords) :
IndexError: index 3 is out of bounds for axis 1 with size 3