0
我是Theano的新手,並試圖將theano矢量標籤轉換爲theano矩陣。 NN應用程序中的一個需要以MxN的二進制矩陣形式的標籤,其中M是樣本的數量,N是類的數量。例如標籤= [0,1,2,1,2,3],banary_labels應該是 [[1,0,0,0]; [0,1,0,0]; [0,0,1,0]; [0,1,0,0]; [0,0,1,0]; [0,0,0,1]如何將整數符號向量的整數標籤轉換爲二進制符號矩陣標籤?
我寫了下面的代碼,但無法弄清楚它是什麼問題
def encode_labels(y,batch_size,max_label):
y=T.ivector('y')
b_y=T.zeros(shape=(batch_size,max_label+1),dtype=theano.config.floatX)
enc,update=theano.scan(lambda i,j:1,
sequences=[T.arange(batch_size),y],
outputs_info=b_y)
encode_l=theano.function(inputs=y,outputs=enc)
return encode_l
y=[0,1,2,1,2,3]
b_y=encode_labels(y,6,3)
print b_y