问题
In CNTK I need a way to convert a vector that contains labels as indices (just a regular vector, not a sparse representation) to a one hot-representation.
Here is an example for 5 classes:
Input
[2, 0, 1, 1]
Desired output:
[[0,0,1,0,0],
[1,0,0,0,0],
[0,1,0,0,0],
[0,1,0,0,0]]
Is there a way without going through Python/numpy?
回答1:
The ‘Value.one_hot’ method does this (converts to a sparseCSC matrix representation internally).
https://www.cntk.ai/pythondocs/cntk.html?highlight=one_hot#cntk.core.Value.one_hot
回答2:
If you're going to use these labels as tags for output layer then probably you'll have to use a numpy array. You should look at this answer.
来源:https://stackoverflow.com/questions/42896773/what-is-the-cntk-way-to-convert-a-vector-that-contains-labels-as-indices-to-a-on