# Theano Tutorial - 03. TensorVariable

From Deep_Learning_Machine_Learning_and_Artificial_Intelligence

There are three types of variable: TensorVariable, TensorConstant, and TensorSharedVariable.

class theano.tensor.TensorVariable(Variable, _tensor_py_operators) class theano.tensor.TensorConstant(Variable, _tensor_py_operators) class theano.tensor.TensorSharedVariable(Variable, _tensor_py_operators)

When we create a tensor, it is an instance of TensorVariable class, with type field has information to TensorType.

>>> a = T.scalar() >>> print(a) <TensorType(float64, scalar)> >>> print(a.type) TensorType(float64, scalar) >>> print(type(a)) <class 'theano.tensor.var.TensorVariable'>

Tensor constant is created with theano.tensor.constant()

>>> const = T.constant(100) >>> print(const) TensorConstant{100} >>> print(const.type) TensorType(int8, scalar) >>> print(type(const)) <class 'theano.tensor.var.TensorConstant'>

Shared variable is created out of numpy ndarray with theano.shared()

>>> b = theano.shared(np.asarray([[1,2],[3,4]])) >>> print(b) <TensorType(int64, matrix)> >>> print(b.type) TensorType(int64, matrix) >>> print(type(b)) <class 'theano.tensor.sharedvar.TensorSharedVariable'>