Theano 简明教程
Theano - Variables
在前面的章节中,在讨论数据类型时,我们创建并使用了 Theano 变量。重申一下,我们使用以下语法在 Theano 中创建一个变量 −
In the previous chapter, while discussing the data types, we created and used Theano variables. To reiterate, we would use the following syntax to create a variable in Theano −
x = theano.tensor.fvector('x')
在此语句中,我们创建了一个 x 类型的变量vector,其中包含 32 位浮点数。我们还将它命名为 x 。名称通常有助于调试。
In this statement, we have created a variable x of type vector containing 32-bit floats. We are also naming it as x. The names are generally useful for debugging.
要声明一个由 32 位整数组成的向量,可以使用以下语法 −
To declare a vector of 32-bit integers, you would use the following syntax −
i32 = theano.tensor.ivector
在此,我们没有为变量指定名称。
Here, we do not specify a name for the variable.
要声明一个由 64 位浮点数组成的三维向量,可以使用以下声明 −
To declare a three-dimensional vector consisting of 64-bit floats, you would use the following declaration −
f64 = theano.tensor.dtensor3
不同类型的构造函数及其数据类型列在下面的表中 −
The various types of constructors along with their data types are listed in the table below −
Constructor |
Data type |
Dimensions |
fvector |
float32 |
1 |
ivector |
int32 |
1 |
fscalar |
float32 |
0 |
fmatrix |
float32 |
2 |
ftensor3 |
float32 |
3 |
dtensor3 |
float64 |
3 |
您可以使用通用的向量构造函数,并通过以下方式明确指定数据类型 −
You may use a generic vector constructor and specify the data type explicitly as follows −
x = theano.tensor.vector ('x', dtype=int32)
在下一章中,我们将了解如何创建共享变量。
In the next chapter, we will learn how to create shared variables.