blog_20160804_1_5154861 1行 Text
Raw
 1
<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">在下载了Theano源码之后,我们同时以开发模式安装了Theano。下面我们来尝试使用Numpy和Theano作一些简单的线性代数运算,熟悉一下这两库的基本使用方法,为下面的神经网络算法学习打好基础。</span>
blog_20160804_2_301884 10行 Python
Raw
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
# 测试开发环境是否正确,定义二维数组及常数与数组相乘
import numpy
from theano import *
import theano.tensor as T

mtx = numpy.asarray([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]])
scale = 2.0
newMtx = scale * mtx

print("二维数组乘以常数: %f, %f" % (newMtx[0, 0], newMtx[2, 0]))
blog_20160804_3_6047959 13行 Python
Raw
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
# 两个数的加法
import numpy
import theano.tensor as T
from theano import function

x = T.dscalar("x")
y = T.dscalar("y")
z = x + y
addition = function([x, y], z)

x = 100
y = 200;
print("加法结果:%d" % addition(x, y))
blog_20160804_4_8098083 13行 Python
Raw
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
# 两个矩阵的加法
import numpy
import theano.tensor as T
from theano import function

x = T.dmatrix("x")
y = T.dmatrix("y")
z = x + y
addition = function([x, y], z)

x = [[1.0, 2.0], [3.0, 4.0]]
y = [[10.0, 20.0], [30.0, 40.0]]
print(addition(x, y))
blog_20160804_5_4433586 2行 Python
Raw
 1
 2
[[ 11. 22.]
[ 33. 44.]]
blog_20160804_6_4880526 7行 Text
Raw
 1
 2
 3
 4
 5
 6
 7
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