分类:版权声明:本文为博主原创文章,未经博主允许不得转载。
目录(?)[+]
本文来自于官方文档
Theano有多种方式进行声明变量。变量也可以进行命名,从而便于debug,而且每一种声明方式都能够接受name的参数。 下面这三种声明方式,声明的是0维的整型变量,它的名字是myvar
返回一个0维的numpy.ndarray。
返回一个1维的numpy.ndarray。
返回一个2维的numpy.ndarray,但是行数保证是1。
返回一个2维的numpy.ndarray,但是列数保证是1。
返回一个2维的numpy.ndarray。
返回一个3维的numpy.ndarray。
返回一个4维的numpy.ndarray。
上文说的dtype在Theano中都有定义。
| 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) |
用法参考如下
from theano.tensor import *x, y, z = dmatrices(3) # creates three matrix Variables with no namesx, y, z = dmatrices('x', 'y', 'z') # creates three matrix Variables named 'x', 'y' and 'z'12341234如果你想要创建一个非标准的类型,那么就只能创造一个你自己定义的TensorType。你需要将dtype和broadcasting pattern传入声明函数中。 下面的例子是,自创一个五维向量。
你也可以重构一个已存在的类型
my_dmatrix = TensorType('float64', (False,)*2)x = my_dmatrix() # allocate a matrix variablePRint my_dmatrix == dmatrix # output is 'True'123123他们会很好地结合起来。
使用的是shared()函数。
这个函数似乎有一些细节,虽然可以这么转化,但是缺少上面声明的一些功能。
返回一个lvector用于表示x的shape
theano.tensor.reshape(x, newshape, ndim=None)11Parameters:
x (某种TensorVariable (或者是可兼容的类型)) – 要进行reshape的变量newshape (lvector (或者是可兼容的类型)) – x的新形状ndim – 可选的- the length that newshape‘s value will have. If this is None, then reshape() will infer it from newshape.Return type:
variable with x’s dtype, but ndim dimensions新闻热点
疑难解答