Here is a code snippet :
seqLen = 4
seq = np.repeat([seqLen-1],seqLen)
print seq
def step2(idx):
if T.lt(idx,seqLen-1):
return T.constant(True)
else:
return T.constant(False)
# return T.lt(idx,seqLen-1)
final,updates = theano.scan(step2,sequences=[T.arange(0,4)]
,outputs_info=None)
iter = theano.function([], outputs=[final],updates=updates)
result = iter()
print 'result', result
The output that I am getting is -
result [array([1, 1, 1, 1], dtype=int8)]
Shouldn't the output be array([1, 1, 1, 0]). Am not able to understand how the sequence 'idx' is being passed to the step function.
Shouldn't it send each value of T.arange(0,4)
at each time step and then T.lt(idx,3)
should return false just for the last time step and true otherwise.
Update: if I modify the step2 function as -
def step2(idx):
return T.lt(idx,seqLen-1)
then I get the correct output as [1,1,1,0]. I need to use the conditional statement as a if condition only. Any help?
Update 2: Instead of using pythonic 'if' construct, I tried theano's 'ifelse' and it worked. But I want to execute a bunch of statements based on the condition and that is why 'ifelse' is not feasible.
Thanks