博客摘自: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. jQuery 插件编程精讲与技巧

    适应的读者: 1.有一定的jquery编程基础但是想在技能上有所提升的人 2.前端开发的程序员 3.对编程感兴趣的学生 为什么要学习jquery插件的编写? 为什么要学习jquery插件的编写?相信这 ...

  2. Javascript 模块化开发上线解决方案

    最近又换部门了,好频繁地说...于是把这段时间搞的小工具们简单整理了一下,作了一个小的总结.这次用一个简单业务demo来向大家介绍一下Javascript模块化开发的方式和自动化合并压缩的一些自己的处 ...

  3. 内网穿透神器ngrok——将本地项目驾到外网

    相信做Web开发的同学们,经常会遇到需要将本地部署的Web应用能够让公网环境直接访问到的情况,例如微信应用调试.支付宝接口调试等.这个时候,一个叫ngrok的神器可能会帮到你,它提供了一个能够在公网安 ...

  4. javascript 连等赋值问题(这是从SegmentFault转过来的一个问题)

    var a = {n:1}; var b = a; // 持有a,以回查 a.x = a = {n:2}; alert(a.x);// --> undefined alert(b.x);// - ...

  5. useradd 添加用户

    功能介绍 useradd命令用于Linux中创建的新的系统用户.useradd可用来建立用户帐号.帐号建好之后,再用passwd设定帐号的密码.而可用userdel删除帐号.使用useradd指令所建 ...

  6. 解决"415 Cannot process the message because the content type 'application/x-www-form-urlencoded' was not the expected type 'text/xml; charset=utf-8'"

    wcf basicHttpBinding content-type    text/xml;charset=utf-8 wsHttpBinding  'application/soap+xml; ch ...

  7. Java的反射机制(Reflection)

    反射机制 指可以在运动时加载.探知.使用编译期间完全未知的类 程序在运行状态中,可以动态加载一个只有名称的类,对于任意一个已加载的类,都能够获取这个类的属性和方法:对于任意一个对象可以调用它的任意一个 ...

  8. fatal: Not a valid object name: 'master'.

    fatal: Not a valid object name: 'master'. the answer is : That is again correct behaviour. Until you ...

  9. Java设计模式(七) 模板模式

    [模板模式]在一个方法中定义了一个算法的骨架,而将一些步骤延迟到子类中.模板方法使得子类可以在不改变算法结构的情况下,重新定义算法中的某些步骤. 1,定义模板类 package com.pattern ...

  10. swift 学习(二)基础知识 (函数,闭包,ARC,柯里化,反射)

    函数 func x(a:Int, b:Int)  {}   func x(a:Int, b:Int) -> Void {}  func x(a:Int, b:Int) ->(Int,Int ...