def ohc(x):
    u = list(set(x))
c = len(u)
X = np.zeros((len(x), c))
for idx, val in enumerate(x):
    for i in range(c):
        if val == u[i]:
            X[idx, i] = 1
return X

def ohc_dict(x):
    elem_to_idx = {}
for e in x:
    if e not in elem_to_idx:
        elem_to_idx[e] = len(elem_to_idx)
c = len(elem_to_idx)
X = np.zeros((len(x), c))
for idx, val in enumerate(x):
    X[idx, elem_to_idx[val]] = 1
return X

def unique_inverse(x):
    uniq, inv = np.unique(x, return_inverse=True)
result = np.zeros((len(x), len(uniq)), dtype=int)
result[np.arange(len(x)), inv] = 1
return result
Как ускорить один горячий код энкодера