what is the one hot encoding for cancer data classification

I am working on a project to classify lung CT dataset using CNN and tensorflow, I know that the order for the category is cancer/no-cancer (only 2 classes), in more than one Github repository I see that they did one hot encoding like the code below:

if label == 1:
label = np.array([0, 1])
elif label == 0:
label = np.array([1, 0])


what makes me confused is: 1 means cancer and 0 means no-cancer, as I understand it should be:

if label == 1:
label = np.array([1, 0])
elif label == 0:
label = np.array([0, 1])


but why they did one hot encoding like this, I don't know I am wrong or there is another thing that I did not understand, can anyone explain it for? or give me a better way to do encoding for my data, but with code?

• If target label is 1,0 then it's already one-hot encoded. Why do it again? – Bal Krishna Jha Sep 15 '18 at 13:28
• No, it's not (0,1), there a data (image files) and the annotation file that for each image ID there is a class with 0 or 1. – Hunar Sep 17 '18 at 8:36

Both ways would work equally, but the way you see in the github repo is more standard.

The standard way of converting a integer label $y_i$ (from 0 to K-1) into a one-hot vector encoding is by creating a all-zero vector of length K, and set the element indexed by $y_i$ to be 1, i.e.

label_one_hot = np.zeros(k)
label_one_hot[label] = 1