Converts integer class labels into binary vectors. Used in neural network outputs and categorical feature encoding.
one_hot([0,2,1,2], n_classes=3) → [[1,0,0],[0,0,1],[0,1,0],[0,0,1]]
Similar Problems
Test Cases (2 visible · 1 hidden)
Case 1: 3-class example
Input: one_hot([0,2,1,2],3)
Expected: [[1, 0, 0], [0, 0, 1], [0, 1, 0], [0, 0, 1]]
Case 2: Binary classification
Input: one_hot([0,1],2)
Expected: [[1, 0], [0, 1]]
⌘↵ Run · ⌘⇧↵ Submit