1 of K coding is a method to create an array in which only certain elements are 1 and the rest are 0. It is also called one hot representation.
It is often used in machine learning.
■Example implementation of 1 of K encoding
An example implementation using numpy is as follows:
import numpy as np
a = np.zeros(5) # Create an array with 5 elements, all with a value of 0
a[3] = 1 # # Set the third element to 1
print(a)