Casting arrays to Theano

I recognize this is a very basic question, but I haven’t been able to find a simple answer from the docs or other answers…but maybe someone could point me in the direction of one?
I am often passing arrays of random variables around between arguments, and would ideally build them in a compact way, as in draw = [a,b,c]. Presently, I am doing this:

import theano.tensor as tt

a = pm.Normal(‘a’, mu=0, sigma=1)
b = pm.Uniform(‘b’, lower=0, upper=1)
c = pm.Uniform(‘c’, lower=0, upper=10)

draw = tt.zeros((3))
draw = tt.set_subtensor(draw[0], a)
draw = tt.set_subtensor(draw[1], b)
draw = tt.set_subtensor(draw[2], c)

But this is cumbersome and verbose, is there a simpler way?

Yes, you can just do the following:

    a = pm.Normal('a', mu=0, sigma=1)
    b = pm.Uniform('b', lower=0, upper=1)
    c = pm.Uniform('c', lower=0, upper=10)

    draw = tt.stack((a, b, c))

Thank you!

1 Like