문제

What is the procedure in Theano for returning the index of a particular value in a Vector? In NumPy, this would be numpy.where(my_array==x). Theano's Tensor.where is a switch statement.

도움이 되었습니까?

해결책

There is 2 behavior of numpy.where(condition, [x ,y]). Theano always support you provide 3 parameter to where(). As said in NumPy doc[1], numpy.where(cond) is equivalent to nonzero().

You can do it like this in Theano:

import theano
import numpy as np
v = np.arange(10)
var = theano.tensor.vector()
out = theano.tensor.eq(var, 2).nonzero()[0]
print out.eval({var: v})

Check line 5. NumPy nonzero() return a tuple. Theano do the same. There is one vector in that tuple per dimensions in the input of nonzero().

[1] http://docs.scipy.org/doc/numpy/reference/generated/numpy.where.html

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top