基础
Theano.Tensor
>>> import theano
>>> import theano.tensor as T
>>> x = T.dmatrix('x')
>>> s = 1 / (1 + T.exp(-x))
>>> logistic = theano.function([x], s)
>>> logistic([[0, 1], [-1, -2]])
array([[ 0.5 , 0.73105858],
[ 0.26894142, 0.11920292]])
>>> x=T.dscalar("xname")
>>> type(x)
<class 'theano.tensor.var.TensorVariable'>
>>> x.type#x是变量,x变量的类型是(float64, scalar)
TensorType(float64, scalar)
共享变量
在不同的函数调用之间共享
>>> from theano import shared
>>> state=shared(0)
>>> inc = T.iscalar('inc')
>>> accumulator = function([inc], state, updates=[(state, state+inc)])#update的格式为(shared-variable, new expression)或directory
>>> accumulator(1)
array(0)#返回原来的state值
>>> state.get_value()
1
>>> accumulator(8)
array(1)
>>> state.get_value()
9
>>> state.set_value(1)
>>> state.get_value()
1
参考
1.图结构
http://www.deeplearning.net/software/theano/extending/graphstructures.html#graphstructures
2.