In [8]:
import theano
from theano import tensor as T
import numpy as np
from theano import function

In [5]:
a = np.asarray([[1., 2], [3, 4], [5, 6]])
print a
print a.shape
print a[2, 0]


[[ 1.  2.]
 [ 3.  4.]
 [ 5.  6.]]
(3, 2)
5.0

In [7]:
a = np.asarray([1.0, 2.0, 3.0])
b = 2.0
print a * b


[ 2.  4.  6.]

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

In [10]:
print f(2, 3)
print f(16.3, 12.1)


5.0
28.4

In [11]:
# T.dscalar is the type we assign to "0-dimensional arrays (scalar) of doubles (d)"
x = T.dscalar('x')
y = T.dscalar('y')

In [12]:
print type(x)
print x.type
print T.dscalar
print x.type is T.dscalar


<class 'theano.tensor.var.TensorVariable'>
TensorType(float64, scalar)
TensorType(float64, scalar)
True

In [13]:
from theano.printing import pp
print pp(z)   # -- prints (x + y)


(x + y)

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


Out[16]:
array(28.4)

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

In [19]:
z.eval({x : np.array([[1,2], [3,4]])
        , y : np.array([[10, 10], [10, 10]])})


Out[19]:
array([[ 11.,  12.],
       [ 13.,  14.]])

In [20]:
# 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 [21]:
x = T.dmatrix('x')
s = 1 / (1 + T.exp(-x))
logistic = function([x], s)
print logistic([[0, 1], [-1, -2]])


[[ 0.5         0.73105858]
 [ 0.26894142  0.11920292]]

In [ ]: