Theano-data-types

提供:Dev Guides
移動先:案内検索

Theano-データ型

Theanoの基本を理解したので、式の作成に使用できるさまざまなデータ型から始めましょう。 次の表は、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

上記のリストは完全ではなく、完全なリストについては、テンソル作成ドキュメントを参照してください。

次に、Theanoでさまざまな種類のデータの変数を作成する方法の例をいくつか示します。

スカラー

スカラー変数を構築するには、構文を使用します-

構文

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

出力

5.0

一次元配列

一次元配列を作成するには、次の宣言を使用します-

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])

出力

(2.0, 5.0, 3.0)
2.0
3.0
*f [3]* を実行すると、ここに示すようにインデックスが範囲外エラーを生成します-
print f([3])

出力

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

二次元配列

二次元配列を宣言するには、次のコードスニペットを使用します-

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

出力

[2, 3]
4

5次元配列

5次元配列を宣言するには、次の構文を使用します-

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])

出力

[5, 6, 7, 8, 9]
13
*tensor5* の代わりにデータ型 *tensor3* を使用して3次元配列を宣言し、 *tensor4* のデータ型を使用して4次元配列を宣言することができます。

複数のコンストラクター

場合によっては、1つの宣言で同じ型の変数を作成することもできます。 あなたは次の構文を使用してそうすることができます-

構文

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])

出力

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