Theano 中将索引向量转换为 0 和 1 矩阵的最佳(优雅和有效)方法是什么,其中每一行都是索引的 N 之一表示?
v = t.ivector() # the vector of indices
n = t.scalar() # the width of the matrix
convert = <your code here>
f = theano.function(inputs=[v, n], outputs=convert)
例子:
n_val = 4
v_val = [1,0,3]
f(v_val, n_val) = [[0,1,0,0],[1,0,0,0],[0,0,0,1]]