theano学习初步(二) 基础Tensor函数
来源:互联网 发布:淘宝认证考试 编辑:程序博客网 时间:2024/04/30 18:28
本文来自于官方文档
Creation(声明)
Theano有多种方式进行声明变量。变量也可以进行命名,从而便于debug,而且每一种声明方式都能够接受name
的参数。
下面这三种声明方式,声明的是0维的整型变量,它的名字是myvar
>>> x = scalar('myvar', dtype='int32')>>> x = iscalar('myvar')>>> x = TensorType(dtype='int32', broadcastable=())('myvar')
Constructors with optional dtype(用dtype参数进行声明)
theano.tensor.scalar(name=None, dtype=config.floatX)
返回一个0维的numpy.ndarray
。
theano.tensor.vector(name=None, dtype=config.floatX)
返回一个1维的numpy.ndarray
。
theano.tensor.row(name=None, dtype=config.floatX)
返回一个2维的numpy.ndarray
,但是行数保证是1。
theano.tensor.col(name=None, dtype=config.floatX)
返回一个2维的numpy.ndarray
,但是列数保证是1。
theano.tensor.matrix(name=None, dtype=config.floatX)
返回一个2维的numpy.ndarray
。
theano.tensor.tensor3(name=None, dtype=config.floatX)
返回一个3维的numpy.ndarray
。
theano.tensor.tensor4(name=None, dtype=config.floatX)
返回一个4维的numpy.ndarray
。
All Fully-Typed Constructors(用完整的类型进行声明)
上文说的dtype
在Theano中都有定义。
Plural Constructors(多重声明)
- iscalars, lscalars, fscalars, dscalars
- ivectors, lvectors, fvectors, dvectors
- irows, lrows, frows, drows
- icols, lcols, fcols, dcols
- imatrices, lmatrices, fmatrices, dmatrices
用法参考如下
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'
Custom tensor types(一般的类型声明)
如果你想要创建一个非标准的类型,那么就只能创造一个你自己定义的TensorType
。你需要将dtype
和broadcasting pattern
传入声明函数中。
下面的例子是,自创一个五维向量。
dtensor5 = TensorType('float64', (False,)*5)x = dtensor5()z = dtensor5('z')
你也可以重构一个已存在的类型
my_dmatrix = TensorType('float64', (False,)*2)x = my_dmatrix() # allocate a matrix variableprint my_dmatrix == dmatrix # output is 'True'
他们会很好地结合起来。
Converting from Python Objects(从Python对象中转移)
使用的是shared()
函数。
x = shared(numpy.random.randn(3,4))
这个函数似乎有一些细节,虽然可以这么转化,但是缺少上面声明的一些功能。
Shaping and Shuffling
theano.tensor.shape(x)
返回一个lvector用于表示x的shape
theano.tensor.reshape(x, newshape, ndim=None)
Parameters:
- 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
0 0
- theano学习初步(二) 基础Tensor函数
- theano学习初步(二) 基础Tensor函数
- theano学习--theano.tensor
- theano学习笔记(二) :基础
- theano学习初步(一)
- theano学习初步(一)
- keras系列二(补充)theano的tensor库
- Theano基础(二)
- theano.tensor模块安排
- Theano学习二----numpy
- 【theano-windows】学习笔记二——theano中的函数和共享参数
- tensorflow学习笔记(二):tensor 变换
- Theano基础、函数与实现
- theano基础学习笔记1
- Theano学习系列(3):符号变量的方法之creat new tensor
- Theano学习系列(4):符号变量的方法之Tensor Reduction
- 深度学习(三)theano学习笔记(2)基础函数-未完待续
- 深度学习(二)theano入门学习
- php获取客户端请求的http头
- 一位资深程序员大牛给予Java初学者的学习路线建议
- 子线程中添加Toast的方法
- Yii2.0中不同业务之间的表导入工作(批量查询, 批量插入)
- 在Mac OS X 中如何查看keychain中已经保存的密码记录
- theano学习初步(二) 基础Tensor函数
- NOIP2008(2)排座椅
- 广播机制
- 测试URL接口的Thread
- 【caffe-Windows】训练自己数据——数据集格式转换
- Python调用已训练好的caffe模型进行分类
- Android设备连接Unity Profiler性能分析器
- 算法学习之素数
- redis的linux下的单机安装、集群安装及测试