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]:
In [4]:
f(16.3, 12.1)
Out[4]:
In [5]:
type(x)
Out[5]:
In [7]:
x.type
Out[7]:
In [8]:
T.dscalar
Out[8]:
In [10]:
x.type is T.dscalar
Out[10]:
In [12]:
print pp(z)
In [14]:
z.eval({x : 16.3, y : 12.1})
Out[14]:
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]:
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])
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]: