.. currentmodule:: tensor
===========================
Basic Tensor Functionality
===========================
Theano supports any kind of Python object, but its focus is support for
symbolic matrix expressions. When you type,
>>> x = T.fmatrix()
the ``x`` is a :class:`TensorVariable` instance.
The ``T.fmatrix`` object itself is an instance of :class:`TensorType`.
Theano knows what type of variable ``x`` is because ``x.type``
points back to ``T.fmatrix``.
This chapter explains the various ways of creating tensor variables,
the attributes and methods of :class:`TensorVariable` and :class:`TensorType`,
and various basic symbolic math and arithmetic that Theano supports for
tensor variables.
.. _libdoc_tensor_creation:
Creation
========
Theano provides a list of predefined tensor types that can be used
to create a tensor variables. Variables can be named to facilitate debugging,
and all of these constructors accept an optional ``name`` argument.
For example, the following each produce a TensorVariable instance that stands
for a 0-dimensional ndarray of integers with the name ``'myvar'``:
>>> x = scalar('myvar', dtype='int32')
>>> x = iscalar('myvar')
>>> x = TensorType(dtype='int32', broadcastable=())('myvar')
Constructors with optional dtype
----------------------------------------
These are the simplest and often-preferred methods for creating symbolic
variables in your code. By default, they produce floating-point variables
(with dtype determined by config.floatX, see :attr:`floatX`) so if you use
these constructors it is easy to switch your code between different levels of
floating-point precision.
.. function:: scalar(name=None, dtype=config.floatX)
Return a Variable for a 0-dimensional ndarray
.. function:: vector(name=None, dtype=config.floatX)
Return a Variable for a 1-dimensional ndarray
.. function:: row(name=None, dtype=config.floatX)
Return a Variable for a 2-dimensional ndarray
in which the number of columns is guaranteed to be 1.
.. function:: col(name=None, dtype=config.floatX)
Return a Variable for a 2-dimensional ndarray
in which the number of columns is guaranteed to be 1.
.. function:: matrix(name=None, dtype=config.floatX)
Return a Variable for a 2-dimensional ndarray
.. function:: tensor3(name=None, dtype=config.floatX)
Return a Variable for a 3-dimensional ndarray
.. function:: tensor4(name=None, dtype=config.floatX)
Return a Variable for a 4-dimensional ndarray
.. #COMMENT
Each of the types described above can be constructed by two methods:
a singular version (e.g., :ref:`dmatrix <libdoc_tensor_creation>`)
and a plural version (:ref:`dmatrices <libdoc_tensor_creation>`).
When called, the singular version takes a single
argument which is the name of the *Variable* we want to make and it
makes a single Variable of that type. The plural version can either take
All Fully-Typed Constructors
----------------------------
The following TensorType instances are provided in the theano.tensor module.
They are all callable, and accept an optional ``name`` argument. So for example:
.. code-block:: python
from theano.tensor import *
x = dmatrix() # creates one Variable with no name
x = dmatrix('x') # creates one Variable with name 'x'
xyz = dmatrix('xyz') # creates one Variable with name 'xyz'
.. #COMMENT
table generated by
$ python Theano/doc/generate_dtype_tensor_table.py
============ =========== ==== =========== =================================
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)
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)
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)
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)
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)
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)
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)
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)
============ =========== ==== =========== =================================
Plural Constructors
--------------------------
There are several constructors that can produce multiple variables at once.
These are not frequently used in practice, but often used in tutorial examples to save space!
.. function:: iscalars, lscalars, fscalars, dscalars
Return one or more scalar variables.
.. function:: ivectors, lvectors, fvectors, dvectors
Return one or more vector variables.
.. function:: irows, lrows, frows, drows
Return one or more row variables.
.. function:: icols, lcols, fcols, dcols
Return one or more col variables.
.. function:: imatrices, lmatrices, fmatrices, dmatrices
Return on
没有合适的资源?快使用搜索试试~ 我知道了~
Theano-0.3.0.tar.gz
0 下载量 95 浏览量
2024-05-13
23:25:41
上传
评论
收藏 827KB GZ 举报
温馨提示
共309个文件
py:175个
txt:122个
cu:4个
Python库是一组预先编写的代码模块,旨在帮助开发者实现特定的编程任务,无需从零开始编写代码。这些库可以包括各种功能,如数学运算、文件操作、数据分析和网络编程等。Python社区提供了大量的第三方库,如NumPy、Pandas和Requests,极大地丰富了Python的应用领域,从数据科学到Web开发。Python库的丰富性是Python成为最受欢迎的编程语言之一的关键原因之一。这些库不仅为初学者提供了快速入门的途径,而且为经验丰富的开发者提供了强大的工具,以高效率、高质量地完成复杂任务。例如,Matplotlib和Seaborn库在数据可视化领域内非常受欢迎,它们提供了广泛的工具和技术,可以创建高度定制化的图表和图形,帮助数据科学家和分析师在数据探索和结果展示中更有效地传达信息。
资源推荐
资源详情
资源评论
收起资源包目录
Theano-0.3.0.tar.gz (309个子文件)
setup.cfg 99B
cuda_ndarray.cu 102KB
conv.cu 55KB
conv_kernel.cu 38KB
conv_full_kernel.cu 18KB
cuda_ndarray.cuh 14KB
MANIFEST.in 128B
PKG-INFO 4KB
PKG-INFO 4KB
basic.py 165KB
test_basic.py 142KB
opt.py 131KB
test_opt.py 93KB
scan.py 88KB
conv.py 79KB
basic_ops.py 75KB
debugmode.py 69KB
basic.py 63KB
nnet.py 59KB
blas_headers.py 58KB
basic.py 56KB
cc.py 52KB
function_module.py 48KB
elemwise.py 47KB
blas.py 45KB
test_scan.py 44KB
elemwise.py 43KB
module.py 40KB
opt.py 39KB
test_nnet.py 35KB
opt.py 34KB
test_basic_ops.py 33KB
test_tutorial.py 31KB
test_pfunc.py 31KB
test_raw_random.py 31KB
cmodule.py 30KB
rng_mrg.py 28KB
test_conv_cuda_ndarray.py 27KB
test_blas.py 27KB
raw_random.py 26KB
test_shared_randomstreams.py 26KB
profilemode.py 26KB
test_module.py 26KB
blas.py 26KB
graph.py 26KB
test_randomstreams.py 26KB
neighbours.py 25KB
test_naacl09.py 24KB
test_function_module.py 22KB
link.py 21KB
printing.py 21KB
test_cuda_ndarray.py 20KB
test_rng_mrg.py 20KB
env.py 19KB
destroyhandler.py 19KB
test_mlp.py 19KB
nnet.py 18KB
test_basic.py 18KB
elemwise_cgen.py 16KB
test_debugmode.py 16KB
distribute_setup.py 15KB
symbolic_module.py 15KB
speed_test_conv.py 13KB
pfunc.py 13KB
test_opt.py 13KB
sigm.py 13KB
downsample.py 13KB
op.py 13KB
test_neighbours.py 13KB
mlp_test.py 13KB
type.py 13KB
mode.py 12KB
type.py 12KB
test_bench_loopfusion.py 12KB
unify.py 12KB
test_conv.py 12KB
compilelock.py 11KB
neighbourhoods.py 11KB
test_shared.py 10KB
test_elemwise.py 10KB
io.py 10KB
utils.py 10KB
configparser.py 10KB
test_destroyhandler.py 10KB
test_inplace_opt_for_value.py 9KB
pycuda_example.py 9KB
test_gradient.py 9KB
nvcc_compiler.py 9KB
multinomial.py 9KB
theano_object.py 8KB
optdb.py 8KB
sharedvalue.py 8KB
__init__.py 8KB
test_cc.py 7KB
test_sharedvar.py 7KB
test_graph.py 7KB
test_basic.py 7KB
test_blas.py 7KB
debug.py 7KB
test_opt.py 6KB
共 309 条
- 1
- 2
- 3
- 4
资源评论
程序员Chino的日记
- 粉丝: 2913
- 资源: 4万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功