博客摘自:Deep learning 第二篇 婴儿学步 Theano如何做算数?

import theano.tensor as T
from theano import function x=T.dscalar('x')
y=T.dscalar('y')
z=x+y
f=function([x,y],z)
print f(2,3)

输出:

5.0

两个矩阵相加:

x=T.dmatrix('x')    #注意这里使用矩阵类型进行格式化
y=T.dmatrix('y')
z=x+y
f2=function([x,y],z) print f2([1,2],[3,4],[10,20],[30,40])

到这里,手册里面出现了3个专业名词:

scalars ----标量:只有大小,没有方向。比如欧几里几何中的两点的距离。
matrix ----矩阵:一种数学标记方法,通常由行和列组成.
vectors ---向量:也常称为矢量,即有方向的量,与标量相对。

可以用来做加法的变量:

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
 
import numpy 

import theano.tensor as T
from theano import function
#from numpy import asarray
#from PIL import Image
#im=Image.open("/Users/chaimwu/Desktop/test.png")
#im.rotate(45).show()
print "OK!"
#print random.rand(4,4) print numpy.asarray([1,2],[3,4],[5,6]).shape
print numpy.asarray([1,2],[3,4],[5,6])[2,0] a = numpy.asarray([1.0, 2.0, 3.0])
b=2.0
print a*b
print b*a x=T.dscalar('x')
y=T.dscalar('y')
z=x+y
f1=function([x,y],z) print f1(1,3) x=T.dmatrix('x')
y=T.dmatrix('y')
z=x+y
f2=function([x,y],z) print f2([1,2],[3,4],[10,20],[30,40]) x=T.dmatrix()
y=T.dmatrix()
z=x+2**y
f3=function([x,y],z) print f3([1,2],[3,4],[10,20],[30,40]) x=T.dvector()
y=T.dvector()
z=2*x+2**y
f4=function([x,y],z) print f4([2,3],[4,5])

Theano tutorial – basic type的更多相关文章

  1. React Tutorial: Basic Concept Of React Component---babel, a translator

    Getting started with react.js: basic concept of React component 1 What is React.js React, or React.j ...

  2. ZetCode PyQt4 tutorial basic painting

    #!/usr/bin/python # -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial In this example, ...

  3. [Web Service] Tutorial Basic Concepts

    WSDL是网络服务描述语言,是一个包含关于web service信息(如方法名,方法参数)以及如何访问它. WSDL是UDDI的一部分. 作为web service 应用程序之间的接口,发音为wiz- ...

  4. Struts 2 Tutorial Basic MVC Architecture

    Model View Controller or MVC as it is popularly called, is a software design pattern for developing ...

  5. paper 167:GPU的使用Theano之tutorial

    Theano之使用GPU 英文版本:http://deeplearning.net/software/theano/tutorial/using_gpu.html          using the ...

  6. 【theano】tutorial

    http://deeplearning.net/software/theano/tutorial/index.html#tutorial

  7. Theano2.1.17-基础知识之剖析theano的函数

    来自:http://deeplearning.net/software/theano/tutorial/profiling.html Profiling Theano function note:该方 ...

  8. Theano2.1.18-基础知识之theano的扩展

    来自:http://deeplearning.net/software/theano/tutorial/extending_theano.html Extending Theano 该教程覆盖了如何使 ...

  9. [转载] CMake Official Tutorial——教程还是官方的好

    CMake官方教程传送门:https://cmake.org/cmake-tutorial/ 以下的内容跟官方教程基本一致,少数地方根据自己的测试有所改动: A Basic Starting Poin ...

随机推荐

  1. ASP.NET 小白从零开始建站简易教程 (一)域名、虚拟主机、FTP上传文件

    只考虑性价比,纯新手实验无备案.跟着步骤走半小时即可收获独立的个人网站一枚! 我的实验站 http://www.bearlab.site/ ⁄(⁄ ⁄•⁄ω⁄•⁄ ⁄)⁄ 目前总价花费86元(域名加虚 ...

  2. Bootstrap系列 -- 44. 分页导航

    带页码的分页导航,可能是最常见的一种分页导航,特别是在列表页内容超多的时候,会给用户提供分页的导航方式.平时很多同学喜欢用div>a和div>span结构来制作带页码的分页导航.不过,在B ...

  3. IL指令大全(转)

    名称 说明 Add 将两个值相加并将结果推送到计算堆栈上. Add.Ovf 将两个整数相加,执行溢出检查,并且将结果推送到计算堆栈上. Add.Ovf.Un 将两个无符号整数值相加,执行溢出检查,并且 ...

  4. 20160205 - Windows 10 家庭版没有组策略

    问题描述:买笔电自带的正版系统,有一个需要使用gpedit.msc,发现并不存在. 解决办法:升级到 Windows 10 专业版

  5. C语言之Sleep函数

    Sleep函数: 功 能: 执行挂起一段时间 用 法: unsigned sleep(unsigned seconds); 注意: 在VC中使用带上头文件#include <windows.h& ...

  6. Exif

    Exif是一种图像文件格式,它的数据存储与JPEG格式是完全相同的.实际上Exif格式就是在JPEG格式头部插入了数码照片的信息,包括拍摄时的光圈.快门.白平衡.ISO.焦距.日期时间等各种和拍摄条件 ...

  7. MATLAB实现频数直方图——hist的使用

      "hist" is short for "Histogram(直方图.柱状图)". 1.N = hist(Y) bins the elements of Y ...

  8. 虚拟机VirtualBox 5.1.0|VBOX

    Oracle VM VirtualBox是一款免费.开源的虚拟机软件,现属于Oracle旗下产品.可以安装Windows.Linux.IBM OS/2.Solaris.BSD等操作系统,具有远端桌面协 ...

  9. stack 栈的实现

    今天晚上去「南哪」听了场AI的讲座,除了话筒真心不给力之外,算是对微软这方面的进展有了更多了解,毕竟是半宣传性质的活动吧. 光听这些是没用的,眼下还是打好基础,多尝试学点新技术,拓宽能力和视野比较重要 ...

  10. python2.X和3.X的一些区别【整理中】

    1.性能 Py3.0运行 pystone benchmark的速度比Py2.5慢30%.Guido认为Py3.0有极大的优化空间,在字符串和整形操作上可  以取得很好的优化结果.  Py3.1性能比P ...