深度学习 - Theano 入门
2016-12-09 00:00
246 查看
参考: http://deeplearning.net/software/theano_versions/dev/tutorial/adding.html
先定义2个symbol(x,y), 然后直接描述表达式(z=x+y),最后用function定义函数出来.
broadcasting. 细节可参考链接, 里面有详细描述.
定义函数
从来没见过这样定义函数的方式, 这编程技巧太强大了.先定义2个symbol(x,y), 然后直接描述表达式(z=x+y),最后用function定义函数出来.
import numpy import theano.tensor as T from theano import function from theano import pp ################################################# x = T.dscalar('x') x.type # TensorType(float64, scalar) y = T.dscalar('y') z = x + y # Elemwise{add,no_inplace}.0 f = function([x, y], z) f(2, 3) # array(5.0) numpy.allclose(f(16.3, 12.1), 28.4) # True pp(z) # (x + y) ################################################# x = T.dvector('x') y = T.dvector('y') z = x + y f = function([x, y], z) f([1, 2], [10, 20]) # [ 11. 22.] ################################################# x = T.dmatrix('x') y = T.dmatrix('y') z = x + y f = function([x, y], z) f([[1, 2], [3, 4]], [[10, 20], [30, 40]]) # [[ 11. 22.] [ 33. 44.]]
参数类型
同一维度的数据往往是直接操作, 如果不同维度的数据, 需要进行扩张, 这里把它叫做broadcasting. 细节可参考链接, 里面有详细描述.
Constructor | dtype | ndim | shape | broadcastable |
---|---|---|---|---|
bscalar | int8 | 0 | () | () |
bvector | int8 | 1 | (?,) | (False,) |
brow | int8 | 2 | (1,?) | (True, False) |
bcol | int8 | 2 | (?,1) | (False, True) |
bmatrix | int8 | 2 | (?,?) | (False, False) |
btensor3 | int8 | 3 | (?,?,?) | (False, False, False) |
btensor4 | int8 | 4 | (?,?,?,?) | (False, False, False, False) |
btensor5 | int8 | 5 | (?,?,?,?,?) | (False, False, False, False, False) |
wscalar | int16 | 0 | () | () |
wvector | int16 | 1 | (?,) | (False,) |
wrow | int16 | 2 | (1,?) | (True, False) |
wcol | int16 | 2 | (?,1) | (False, True) |
wmatrix | int16 | 2 | (?,?) | (False, False) |
wtensor3 | int16 | 3 | (?,?,?) | (False, False, False) |
wtensor4 | int16 | 4 | (?,?,?,?) | (False, False, False, False) |
wtensor5 | int16 | 5 | (?,?,?,?,?) | (False, False, False, False, False) |
iscalar | int32 | 0 | () | () |
ivector | int32 | 1 | (?,) | (False,) |
irow | int32 | 2 | (1,?) | (True, False) |
icol | int32 | 2 | (?,1) | (False, True) |
imatrix | int32 | 2 | (?,?) | (False, False) |
itensor3 | int32 | 3 | (?,?,?) | (False, False, False) |
itensor4 | int32 | 4 | (?,?,?,?) | (False, False, False, False) |
itensor5 | int32 | 5 | (?,?,?,?,?) | (False, False, False, False, False) |
lscalar | int64 | 0 | () | () |
lvector | int64 | 1 | (?,) | (False,) |
lrow | int64 | 2 | (1,?) | (True, False) |
lcol | int64 | 2 | (?,1) | (False, True) |
lmatrix | int64 | 2 | (?,?) | (False, False) |
ltensor3 | int64 | 3 | (?,?,?) | (False, False, False) |
ltensor4 | int64 | 4 | (?,?,?,?) | (False, False, False, False) |
ltensor5 | int64 | 5 | (?,?,?,?,?) | (False, False, False, False, False) |
dscalar | float64 | 0 | () | () |
dvector | float64 | 1 | (?,) | (False,) |
drow | float64 | 2 | (1,?) | (True, False) |
dcol | float64 | 2 | (?,1) | (False, True) |
dmatrix | float64 | 2 | (?,?) | (False, False) |
dtensor3 | float64 | 3 | (?,?,?) | (False, False, False) |
dtensor4 | float64 | 4 | (?,?,?,?) | (False, False, False, False) |
dtensor5 | float64 | 5 | (?,?,?,?,?) | (False, False, False, False, False) |
fscalar | float32 | 0 | () | () |
fvector | float32 | 1 | (?,) | (False,) |
frow | float32 | 2 | (1,?) | (True, False) |
fcol | float32 | 2 | (?,1) | (False, True) |
fmatrix | float32 | 2 | (?,?) | (False, False) |
ftensor3 | float32 | 3 | (?,?,?) | (False, False, False) |
ftensor4 | float32 | 4 | (?,?,?,?) | (False, False, False, False) |
ftensor5 | float32 | 5 | (?,?,?,?,?) | (False, False, False, False, False) |
cscalar | complex64 | 0 | () | () |
cvector | complex64 | 1 | (?,) | (False,) |
crow | complex64 | 2 | (1,?) | (True, False) |
ccol | complex64 | 2 | (?,1) | (False, True) |
cmatrix | complex64 | 2 | (?,?) | (False, False) |
ctensor3 | complex64 | 3 | (?,?,?) | (False, False, False) |
ctensor4 | complex64 | 4 | (?,?,?,?) | (False, False, False, False) |
ctensor5 | complex64 | 5 | (?,?,?,?,?) | (False, False, False, False, False) |
zscalar | complex128 | 0 | () | () |
zvector | complex128 | 1 | (?,) | (False,) |
zrow | complex128 | 2 | (1,?) | (True, False) |
zcol | complex128 | 2 | (?,1) | (False, True) |
zmatrix | complex128 | 2 | (?,?) | (False, False) |
ztensor3 | complex128 | 3 | (?,?,?) | (False, False, False) |
ztensor4 | complex128 | 4 | (?,?,?,?) | (False, False, False, False) |
ztensor5 | complex128 | 5 | (?,?,?,?,?) | (False, False, False, False, False) |
相关文章推荐
- 初始安装httpd服务启动时的报错
- 将 SeeedArchLink 变为 micro:bit(micropython)
- Windows下的Redis安装教程
- id初期游戏编程的9大法则_广州达内Unity3D培训机构
- 腾讯的《Pokemon Go》要来了,支付宝别跑!_广州达内Unity3D培训机构
- 《最终幻想15》更新计划:开启新游戏+模式_广州达内Unity3D培训机构
- macOS 下的 homebrew
- Docker 命令
- Git上传本地项目到git@OSC
- Linux Perl 升级
- 记录nodejs与mysql
- 一、NSString
- 随机数
- 地图
- SpringBoot 07 之JPA使用
- centos 7版本防火墙详细说明
- centos安装jdk,tomcat,mysql
- mac 设置连接ssh服务器免密码
- 脉搏制造网CEO李春伟:打造制造业垂直B2B电商平台助力中小企业
- java 面试核心内容