2

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?

Anna Kim
  • 61
  • 2

2 Answers2

2

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

chrisbasoglu
  • 357
  • 1
  • 9
0

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.

Community
  • 1
  • 1
Ashutosh Baheti
  • 410
  • 4
  • 20