This is shown in the theano tutorials, for example here.
The first argument of the function is automatically taken from the sequences
argument of scan, if provided.
For example, suppose you want to add to every element of a vector x
its corresponding index.
You could do it with theano.scan
like this:
import theano
import theano.tensor as T
x = T.dvector('x')
def step(idx, array):
return array[idx] + idx
results, updates = theano.scan(fn=step,
sequences=T.arange(x.shape[0]),
non_sequences=[x])
f = theano.function([x], results)
f([1., 0., 2.13])
# array([ 1. , 1. , 4.13])
so basically: mind the order of the arguments of the function you give to scan
, as they are passed in a specific order.
You can see exactly what order in the relevant documentation page of scan.