Theano(2) Algebra

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])) # 写一个例子测试一下

猜你喜欢

转载自blog.csdn.net/shangyt/article/details/47706925