broadcasting Theano vs. Numpy
broadcasting Theano vs. Numpy
broadcast mechanism allows a scalar may be added to a matrix, a vector to a matrix or a scalar to a vecotor.
Examples
T
and F
stands for True
and False
respectively, denoting which dimension can be broadcasted.
Diference
- numpy broadcast dynamically;
- theano needs to knows, for any operations which supports broadcasting, which dimensions will need to be broadcasted.
Numpy Broadcasting
broadcasting
describe how numpy treats arrays with difference shapes during arithmetic operations:
the smaller array is broadcast
across the larger array so that they have compatible shapes
Simple Case
in this case, the two arrays must have exactly the same shape:
a=np.array([1.0,2.0,3.0])
b=np.array([2.0,2.0,2.0])
print a*b
>>> array([2., 4., 6.])
numpy broadcast mechanism relaxes this constraint when the arrays' shape meet certain constraints:
- they are equal, or
- one of them is 1
a=np.array([1.0,2.0,3.0])
b=2
print a*b
>>> array([2., 4., 6.])
rules
Image (3d array): 256 x 256 x 3
Scale (1d array): 3
Result (3d array): 256 x 256 x 3
A (4d array): 8 x 1 x 6 x 1
B (3d array): 7 x 1 x 5
Result (4d array): 8 x 7 x 6 x 5
more examples
A (2d array): 5 x 4
B (1d array): 1
Result (2d array): 5 x 4
A (2d array): 5 x 4
B (1d array): 4
Result (2d array): 5 x 4
A (3d array): 15 x 3 x 5
B (3d array): 15 x 1 x 5
Result (3d array): 15 x 3 x 5
A (3d array): 15 x 3 x 5
B (2d array): 3 x 5
Result (3d array): 15 x 3 x 5
A (3d array): 15 x 3 x 5
B (2d array): 3 x 1
Result (3d array): 15 x 3 x 5
broadcasting Theano vs. Numpy的更多相关文章
- 关于PDNN、Theano、Numpy以及Scipy的安装
最近为了用下PDNN,先得安装这玩意,不装不知道,一装吓一跳,依赖关系也太多了吧,顿时有种贵圈真乱的感觉,如图1. 不过这B还得装下去. 图1 安装PDNN的依赖关系 之前也碰了好多问题,不过各种参考 ...
- Theano 学习笔记(一)
Theano 学习笔记(一) theano 为什么要定义共享变量? 定义共享变量的原因在于GPU的使用,如果不定义共享的话,那么当GPU调用这些变量时,遇到一次就要调用一次,这样就会花费大量时间在数据 ...
- python 之 theano学习:
(1)theano主要支持符号矩阵表达式 (2)theano与numpy中都有broadcasting:numpy中是动态的,而theano需要在这之前就知道是哪维需要被广播.针对不同类型的数据给出如 ...
- theano支持的数组、向量、矩阵表达式
1)theano主要支持符号矩阵表达式 (2)theano与numpy中都有broadcasting:numpy中是动态的,而theano需要在这之前就知道是哪维需要被广播.针对不同类型的数据给出如下 ...
- ubuntu系统theano和keras的安装
说明:系统是unbuntu14.04LTS,32位的操作系统,以前安装了python3.4,现在想要安装theano和keras.步骤如下: 1,安装pip sudo apt-get install ...
- theano 实现图像局部对比度归一化
很多时候我们需要对图像进行局部对比度归一化,比如分块CNN的预处理阶段.theano对此提供了一些比较方便的操作. 局部归一化的一种简单形式为: 其中μ和σ分别为局部(例如3x3的小块)的均值和标准差 ...
- theano中的dimshuffle
theano中的dimshuffle函数用于对张量的维度进行操作,可以增加维度,也可以交换维度,删除维度. 注意的是只有shared才能调用dimshuffle() 'x'表示增加一维,从0d sca ...
- Theano2.1.5-基础知识之打印出theano的图
来自:http://deeplearning.net/software/theano/tutorial/printing_drawing.html Printing/Drawing Theano gr ...
- Theano2.1.18-基础知识之theano的扩展
来自:http://deeplearning.net/software/theano/tutorial/extending_theano.html Extending Theano 该教程覆盖了如何使 ...
随机推荐
- 前端导出Excel兼容写法
今天整理出在Web前端导出Excel的写法,写了一个工具类,对各个浏览器进行了兼容. 首先,导出的数据来源可能有两种: 1. 页面的HTML内容(一般是table) 2. 纯数据 PS:不同的数据源, ...
- JQuery效果-淡入淡出、滑动、动画
一.JQuery Fading方法 JQuery 有四种fade方法 1.fadeIn() 淡入 对应也有$(selector).fadeIn(speed, ...
- 深入理解javascript选择器API系列第二篇——getElementsByClassName
× 目录 [1]使用 [2]classList [3]扩展 前面的话 既然有getElementById()和getElementsByTagName()方法,为什么没有getElementsByCl ...
- iOS陀螺仪 参数意义
self.mManager = [[CMMotionManager alloc]init]; self.mManager.deviceMotionUpdateInterval = 0.5; if (s ...
- SQLite学习笔记(十二)&&虚拟机指令
上篇文章简单讨论了虚拟机的原理,这篇文章我们详细讨论下指令,具体从几种典型的SQL语句来看看每种SQL对应的指令流,以及每个指令的含义.通过explain语句,可以看到语句对应的指令流:通过pragm ...
- 简体中国版文档的Markdown语法
Markdown文件 注意︰这是简体中国版文档的Markdown语法.如果你正在寻找英语版文档.请参阅Markdown︰ Markdown: Syntax. Markdown: Syntax 概述 哲 ...
- ubuntu kylin 14.04安装搜狗输入法
1.卸载原有的输入法,fcitx或ibus.如卸载fcitx: sudo apt-get remove fcitx*(如不需保留配置文件用purge) sudo apt-get autoremove( ...
- Java Generics and Collections-2.3
2.3 Wildcards with super 这里就直接拿书上的例子好了,这是Collections里面的一个方法: public static <T> void copy(List& ...
- 基于英特尔® 至强™ 处理器 E5 产品家族的多节点分布式内存系统上的 Caffe* 培训
原文链接 深度神经网络 (DNN) 培训属于计算密集型项目,需要在现代计算平台上花费数日或数周的时间方可完成. 在最近的一篇文章<基于英特尔® 至强™ E5 产品家族的单节点 Caffe 评分和 ...
- Selenium-java-web常用操作---2
都是些的方法,一起交流交流 上传文件 private static void action2() { // TODO Auto-generated method stub WebElement ele ...