In [1]:
# http://deeplearning.net/software/theano/tutorial/index.html
from theano import *
import theano.tensor as T

In [2]:
x = T.dscalar('x')
y = T.dscalar('y')
z = x + y
f = function([x, y], z)

In [3]:
f(2, 3)


Out[3]:
array(5.0)

In [4]:
f(16.3, 12.1)


Out[4]:
array(28.4)

In [5]:
type(x)


Out[5]:
theano.tensor.var.TensorVariable

In [7]:
x.type


Out[7]:
TensorType(float64, scalar)

In [8]:
T.dscalar


Out[8]:
TensorType(float64, scalar)

In [10]:
x.type is T.dscalar


Out[10]:
True

In [12]:
print pp(z)


(x + y)

In [14]:
z.eval({x : 16.3, y : 12.1})


Out[14]:
array(28.4)

In [15]:
x = T.dmatrix('x')
y = T.dmatrix('y')
z = x + y
f = function([x, y], z)

In [17]:
f([[1,2], [3,4]], [[10,20], [30,40]])


Out[17]:
array([[ 11.,  22.],
       [ 33.,  44.]])

The following types are available:

byte: bscalar, bvector, bmatrix, brow, bcol, btensor3, btensor4
16-bit integers: wscalar, wvector, wmatrix, wrow, wcol, wtensor3, wtensor4
32-bit integers: iscalar, ivector, imatrix, irow, icol, itensor3, itensor4
64-bit integers: lscalar, lvector, lmatrix, lrow, lcol, ltensor3, ltensor4
float: fscalar, fvector, fmatrix, frow, fcol, ftensor3, ftensor4
double: dscalar, dvector, dmatrix, drow, dcol, dtensor3, dtensor4
complex: cscalar, cvector, cmatrix, crow, ccol, ctensor3, ctensor4


In [18]:
a = T.vector()

In [19]:
out = a + a ** 10

In [20]:
f = function([a], out)

In [22]:
print f([0, 1, 2])


[    0.     2.  1026.]

In [23]:
b = T.vector()

In [24]:
out = a**2 + b**2 + 2*a*b

In [27]:
f = function([a,b], out)

In [28]:
f([1,2], [4,5],)


Out[28]:
array([ 25.,  49.])