我有一个theano张量向量 next_probs 类似 [0.222, 0.34342, 0.41324, 0.1231, ...] ,这是以下函数的输出:
next_probs
[0.222, 0.34342, 0.41324, 0.1231, ...]
next_probs = tensor.nnet.softmax(logit)
logit 是一个与 next_probs 具有相同尺寸的矢量 .
logit
如何在 next_probs 向量中将一个特定值更改为 1 ,将其他值更改为 0 ?
1
0
你想要改变什么 Value ?如果你只想要一个与 next_probs 具有相同尺寸的矢量,你可以使用 zeros 和 set_subtensor 如下
zeros
set_subtensor
ret = T.zeros(next_probs.shape) ret = T.set_subtensor(ret[index],1)
如果你想在分类模型中使用它,你需要 next_probs 中概率最高的类变为1而其他类变为0这是我的另一个答案:
ret = T.zeros(next_probs.shape) ret = T.set_subtensor(ret[T.argmax(next_probs)],1)
ret 是一个类别为1的向量,概率最高,其他为0
ret
1 回答
你想要改变什么 Value ?如果你只想要一个与
next_probs
具有相同尺寸的矢量,你可以使用zeros
和set_subtensor
如下如果你想在分类模型中使用它,你需要
next_probs
中概率最高的类变为1而其他类变为0这是我的另一个答案:ret
是一个类别为1的向量,概率最高,其他为0