Theano

基础

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值