Reputation: 3781
I have a theano tensor vector next_probs
something like [0.222, 0.34342, 0.41324, 0.1231, ...]
, which is the output of the following function:
next_probs = tensor.nnet.softmax(logit)
logit
is a vector which has the same dimension as next_probs
.
How can I change one specific value to 1
, and the others to 0
in next_probs
vector?
Upvotes: 0
Views: 407
Reputation: 3291
What value specifically you want to change? if you just want have a vector which have same dimension as next_probs
you can use zeros
and set_subtensor
like below
ret = T.zeros(next_probs.shape)
ret = T.set_subtensor(ret[index],1)
If you want to use this in classification model, and you need the class with highest probability in next_probs
become 1 and the others become 0 this is my other answer:
ret = T.zeros(next_probs.shape)
ret = T.set_subtensor(ret[T.argmax(next_probs)],1)
ret
is a vector with 1 in the class with highest probability, and 0 for the others
Upvotes: 1