Theano(2) Algebra

本文介绍了如何使用Theano进行向量和矩阵的基本运算,包括向量加法、矩阵加法等,并通过具体实例展示了如何定义变量、执行运算及创建函数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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])) # 写一个例子测试一下
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值