1
テンソルフローを使用するには、クラス用に1つのホットベクトルが必要です。Python Broadcasting:One-Hotベクトルを埋め込む際にNumPyの速度を引き出す方法は?
私はワンホットベクトルを作成するために次のコードを持っていますが、それはnumpy放送のために熟しているようです。
def classVector2oneHot(classVector):
uniques = np.asarray(list(set(classVector)))
one_hot_array = np.zeros(shape=(classVector.shape[0],uniques.shape[0]),dtype=np.float32)
starting_index = np.min(uniques)
# where broadcasting seems like it should be possible, somehow...
for i in range(len(one_hot_array)):
one_hot_array[i,classVector[i]-starting_index] = 1
return one_hot_array