您的位置:首页 > 其它

Theano(2) Algebra

2015-08-16 21:45 197 查看
Algebra 代数 [ˈældʒəbrə]
http://deeplearning.net/software/theano/tutorial/adding.html
(1)Scalars 向量加法

x = theano.tensor.dscalar('x')

y = theano.tensor.dscalar('y')

z = x + y

f = theano.function([x, y], z)

(2)矩阵加法

x = theano.tensor.dmatrix('x')

y = theano.tensor.dmatrix('y')

z = x + y

f = theano.function([x, y], z)

(3)练习

import theano

a = theano.tensor.vector() # 容易忘记写括号

b = theano.tensor.vector() # 同上

out = a**2 + b**2 + 2*a*b # 注意书写格式

f = theano.function([a, b], out) # 注意向量a和b的写法

print(f([1, 2], [4, 5])) # 写一个例子测试一下
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: