你的第一个 theano 计划
在这个例子中,我们将编译计算求和和给出两个实数的差异的函数。
from __future__ import print_function
import theano
import theano.tensor as T
#define two symbolic scalar
s_x = T.fscalar()
s_y = T.fscalar()
#compute something
s_sum = s_x + s_y
s_diff = s_x - s_y
#compile a function that adds two number
#theano will call system compiler at here
fn_add = theano.function(inputs=[s_x, s_y], outputs=s_sum)
fn_diff = theano.function(inputs=[s_x, s_y], outputs=s_diff)
#call the compiled functions
print(fn_add(2., 2.)) #4.
print(fn_diff(2., 2.)) #0.