from sklearn import preprocessing
import numpy as np
enc = preprocessing.OneHotEncoder(categories='auto')
enc.fit([[1],[2],[3]])
result =enc.transform([[1],[3],[2]])
print(result.toarray())
a = [[0.2,0.3,0.5],
[0.7,0.3,0.5],
[0.7,0.9,0.5]
]
def props_to_onehot(props):
if isinstance(props, list):
props = np.array(props)
a = np.argmax(props, axis=1)
b = np.zeros((len(a), props.shape[1]))
b[np.arange(len(a)), a] = 1
return b
print(props_to_onehot(a))
print("----softmax -> label ----")
print(enc.inverse_transform(props_to_onehot(a)))