首页 文章

改变theano张量向量中的值

提问于
浏览
0

我有一个theano张量向量 next_probs 类似 [0.222, 0.34342, 0.41324, 0.1231, ...] ,这是以下函数的输出:

next_probs = tensor.nnet.softmax(logit)

logit 是一个与 next_probs 具有相同尺寸的矢量 .

如何在 next_probs 向量中将一个特定值更改为 1 ,将其他值更改为 0

1 回答

  • 1

    你想要改变什么 Value ?如果你只想要一个与 next_probs 具有相同尺寸的矢量,你可以使用 zerosset_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

相关问题