Theano 简明教程
Theano - Data Types
现在,你已经了解了 Theano 的基础知识,让我们开始了解可用于创建表达式的不同数据类型。下表为你提供了 Theano 中定义的数据类型的部分列表。
Now, that you have understood the basics of Theano, let us begin with the different data types available to you for creating your expressions. The following table gives you a partial list of data types defined in Theano.
Data type |
Theano type |
Byte |
bscalar, bvector, bmatrix, brow, bcol, btensor3, btensor4, btensor5, btensor6, btensor7 |
16-bit integers |
wscalar, wvector, wmatrix, wrow, wcol, wtensor3, wtensor4, wtensor5, wtensor6, wtensor7 |
32-bit integers |
iscalar, ivector, imatrix, irow, icol, itensor3, itensor4, itensor5, itensor6, itensor7 |
64-bit integers |
lscalar, lvector, lmatrix, lrow, lcol, ltensor3, ltensor4, ltensor5, ltensor6, ltensor7 |
float |
fscalar, fvector, fmatrix, frow, fcol, ftensor3, ftensor4, ftensor5, ftensor6, ftensor7 |
double |
dscalar, dvector, dmatrix, drow, dcol, dtensor3, dtensor4, dtensor5, dtensor6, dtensor7 |
complex |
cscalar, cvector, cmatrix, crow, ccol, ctensor3, ctensor4, ctensor5, ctensor6, ctensor7 |
以上列表不会穷尽,读者可参考张量创建文档获取完整列表。
The above list is not exhaustive and the reader is referred to the tensor creation document for a complete list.
接下来,我将提供一些在 Theano 中创建不同类型数据变量的示例。
I will now give you a few examples of how to create variables of various kinds of data in Theano.
One-dimensional Array
要创建一个一维数组,请使用以下声明 −
To create a one dimensional array, use the following declaration −
Example
f = theano.tensor.vector
f = (2.0, 5.0, 3.0)
print (f)f = theano.tensor.vector
f = (2.0, 5.0, 3.0)
print (f)
print (f[0])
print (f[2])
Two-dimensional Array
要声明一个二维数组,可以使用以下代码片段 −
To declare a two-dimensional array you would use the following code snippet −
5-dimensional Array
要声明一个五维数组,请使用以下语法 −
To declare a 5-dimensional array, use the following syntax −
Plural Constructors
有时,你可能希望在单一声明中创建相同类型的变量。你可以使用以下语法执行此操作 −
Sometimes, you may want to create variables of the same type in a single declaration. You can do so by using the following syntax −