One Hot
labels holds class numbers from 0 to n - 1. Return a 2-D tensor with one row per label and n columns: all zeros, except for a 1 in the column of that label.
Example 1
labels [0,2,1]
n 3
returns [[1,0,0],[0,0,1],[0,1,0]]
Constraints
- 1 to 6 labels
2 <= n <= 6
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More PyTorch problems
- Only the PositivesEasy
- Rows That Sum to OneEasy
- Stack the RowsEasy
- The First GradientEasy
- The k LargestEasy
- A Moving AverageMedium
- Count the ParametersMedium
- Cross-EntropyMedium