I'm working on an image classification problem where I got the train labels as a 1-D numpy array, like [1,2,3,2,2,2,4,4,3,1]
. I used
train_y = []
for label in train_label:
if label == 0:
train_y.append([1,0,0,0])
elif label == 1:
train_y.append([0,1,0,0])
elif label == 2:
train_y.append([0,0,1,0])
elif label == 3:
train_y.append([0,0,0,1])
Also I need the len(one_hot_array) = set(train_labels)
,
but this is not a good method. Please recommend a good method to do so.