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]
In [7]:
a = np.asarray([1.0, 2.0, 3.0])
b = 2.0
print a * b
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)
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
In [13]:
from theano.printing import pp
print pp(z) # -- prints (x + y)
In [16]:
z = x + y
z.eval({x : 16.3, y : 12.1})
Out[16]:
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]:
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]])
In [ ]: