0

doing MNIST tutorial without any MLframe, but got stuck in one hot encoding stage

y contains label data of digits images

0, 1, 2, 3, 4, 5, 6, 7, 8, 9

and its size is (10000, )

I want to convert each category numbers to one hot encoding array

0 : 1 0 0 0 0 0 0 0 0 0 0
1 : 0 1 0 0 0 0 0 0 0 0 0
2 : 0 0 1 0 0 0 0 0 0 0 0 and so on

so I made a code

import numpy as np
y_one=np.zeros(y.size, 10)
y_one[np.arange(y.size), y]=1

it says 'data type not understood'

How to implement one hot encoding without sklearn or tf in this case?

1 Answers1

0

Pass tuple of ints for shape parameter of np.zeros function

y_one = np.zeros((y.size, 10))
Dishin H Goyani
  • 7,195
  • 3
  • 26
  • 37