Theano-数据类型

Theano-数据类型 (Theano - Data Types)

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.

现在,您已经了解了Theano的基础,让我们从可用于创建表达式的不同数据类型开始。 下表为您提供了Theano中定义的数据类型的部分列表。

Data typeTheano 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

数据类型 茶野型
字节

bscalar,bvector,bmatrix,眉毛,bcol,btensor3,btensor4,btensor5,btensor6,btensor7

16位整数

wscalar,wvector,wmatrix,wrow,wcol,wtensor3,wtensor4,wtensor5,wtensor6,wtensor7

32位整数

iscalar,ivector,imatrix,irow,icol,itensor3,itensor4,itensor5,itensor6,itensor7

64位整数

lscalar,lvector,lmatrix,row,lcol,ltensor3,ltensor4,ltensor5,ltensor6,ltensor7

浮动

fscalar,fvector,fmatrix,frow,fcol,ftensor3,ftensor4,ftensor5,ftensor6,ftensor7

dscalar,dvector,dmatrix,drow,dcol,dtensor3,dtensor4,dtensor5,dtensor6,dtensor7

复杂

cscalar,cvector,cmatrix,乌鸦,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.

上面的列表并不详尽,读者可以参考张量创建文档以获取完整列表。

I will now give you a few examples of how to create variables of various kinds of data in Theano.

现在,我将为您提供一些有关如何在Theano中创建各种数据变量的示例。

标量 (Scalar)

To construct a scalar variable you would use the syntax −

要构建标量变量,您可以使用语法-

句法 (Syntax)


x = theano.tensor.scalar ('x')
x = 5.0
print (x)

输出量 (Output)


5.0

一维数组 (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])

输出量 (Output)


(2.0, 5.0, 3.0)
2.0
3.0

If you do f[3] it would generate an index out of range error as shown here −

如果执行f [3] ,则会生成索引超出范围的错误,如下所示-


print f([3])

输出量 (Output)


IndexError                          Traceback (most recent call last)
<ipython-input-13-2a9c2a643c3a> in <module>
   4 print (f[0])
   5 print (f[2])
----> 6 print (f[3])
IndexError: tuple index out of range

二维阵列 (Two-dimensional Array)

To declare a two-dimensional array you would use the following code snippet −

要声明一个二维数组,您将使用以下代码片段-

(Example)


m = theano.tensor.matrix
m = ([2,3], [4,5], [2,4])
print (m[0])
print (m[1][0])

输出量 (Output)


[2, 3]
4

5维数组 (5-dimensional Array)

To declare a 5-dimensional array, use the following syntax −

要声明5维数组,请使用以下语法-

(Example)


m5 = theano.tensor.tensor5
m5 = ([0,1,2,3,4], [5,6,7,8,9], [10,11,12,13,14])
print (m5[1])
print (m5[2][3])

输出量 (Output)


[5, 6, 7, 8, 9]
13

You may declare a 3-dimensional array by using the data type tensor3 in place of tensor5, a 4-dimensional array using the data type tensor4, and so on up to tensor7.

你可以通过代替tensor5的使用数据类型tensor3,使用数据类型tensor4 4维阵列,并依此类推,直到tensor7声明一个3维阵列。

多个构造函数 (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 −

有时,您可能希望在单个声明中创建相同类型的变量。 您可以使用以下语法来做到这一点-

句法 (Syntax)


from theano.tensor import * x, y, z = dmatrices('x', 'y', 'z') 
x = ([1,2],[3,4],[5,6]) 
y = ([7,8],[9,10],[11,12]) 
z = ([13,14],[15,16],[17,18]) 
print (x[2]) 
print (y[1]) 
print (z[0])

输出量 (Output)


[5, 6] 
[9, 10] 
[13, 14]

翻译自: https://www.tutorialspoint.com/theano/theano_data_types.htm

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值