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

  1. numpy broadcast dynamically;
  2. 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:

  1. they are equal, or
  2. 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的更多相关文章

  1. 关于PDNN、Theano、Numpy以及Scipy的安装

    最近为了用下PDNN,先得安装这玩意,不装不知道,一装吓一跳,依赖关系也太多了吧,顿时有种贵圈真乱的感觉,如图1. 不过这B还得装下去. 图1 安装PDNN的依赖关系 之前也碰了好多问题,不过各种参考 ...

  2. Theano 学习笔记(一)

    Theano 学习笔记(一) theano 为什么要定义共享变量? 定义共享变量的原因在于GPU的使用,如果不定义共享的话,那么当GPU调用这些变量时,遇到一次就要调用一次,这样就会花费大量时间在数据 ...

  3. python 之 theano学习:

    (1)theano主要支持符号矩阵表达式 (2)theano与numpy中都有broadcasting:numpy中是动态的,而theano需要在这之前就知道是哪维需要被广播.针对不同类型的数据给出如 ...

  4. theano支持的数组、向量、矩阵表达式

    1)theano主要支持符号矩阵表达式 (2)theano与numpy中都有broadcasting:numpy中是动态的,而theano需要在这之前就知道是哪维需要被广播.针对不同类型的数据给出如下 ...

  5. ubuntu系统theano和keras的安装

    说明:系统是unbuntu14.04LTS,32位的操作系统,以前安装了python3.4,现在想要安装theano和keras.步骤如下: 1,安装pip sudo apt-get install ...

  6. theano 实现图像局部对比度归一化

    很多时候我们需要对图像进行局部对比度归一化,比如分块CNN的预处理阶段.theano对此提供了一些比较方便的操作. 局部归一化的一种简单形式为: 其中μ和σ分别为局部(例如3x3的小块)的均值和标准差 ...

  7. theano中的dimshuffle

    theano中的dimshuffle函数用于对张量的维度进行操作,可以增加维度,也可以交换维度,删除维度. 注意的是只有shared才能调用dimshuffle() 'x'表示增加一维,从0d sca ...

  8. Theano2.1.5-基础知识之打印出theano的图

    来自:http://deeplearning.net/software/theano/tutorial/printing_drawing.html Printing/Drawing Theano gr ...

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

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

随机推荐

  1. 如何在Node.js中合并两个复杂对象

    通常情况下,在Node.js中我们可以通过underscore的extend或者lodash的merge来合并两个对象,但是对于像下面这种复杂的对象,要如何来应对呢? 例如我有以下两个object: ...

  2. arcgis 按面积分割, 按比例分割面积,按等份批量面积分割工具

    arcgis 按面积分割, 按比例分割面积,按等份批量面积分割工具 视频下载:https://yunpan.cn/cvujkpKIqwccn  访问密码 e9f4

  3. SDK接入(2)之Android Google Play内支付(in-app Billing)接入

    SDK接入(2)之Android Google Play内支付(in-app Billing)接入 继上篇SDK接入(1)之Android Facebook SDK接入整理完Facebook接入流程之 ...

  4. React Native知识9-ScrollView组件

    一个包装了平台的ScrollView(滚动视图)的组件,同时还集成了触摸锁定的“响应者”系统. 记住ScrollView必须有一个确定的高度才能正常工作,因为它实际上所做的就是将一系列不确定高度的子组 ...

  5. android MD5加密

    public class MD5Uutils {    //MD5加密,32位    public static String MD5(String str) {        MessageDige ...

  6. [MySQL Reference Manual]15. 其他存储引擎

    15. 其他存储引擎 15. 其他存储引擎 15.1 设置存储引擎 15.2 MyISAM存储引擎 15.2.1 MyISAM启动选项 15.2.2 Key的空间要求 15.2.3 MyISAM表存储 ...

  7. sqoop:Failed to download file from http://hdp01:8080/resources//oracle-jdbc-driver.jar due to HTTP error: HTTP Error 404: Not Found

    环境:ambari2.3,centos7,sqoop1.4.6 问题描述:通过ambari安装了sqoop,又添加了oracle驱动配置,如下: 保存配置后,重启sqoop报错:http://hdp0 ...

  8. python-socket模块

    socket server #!/usr/bin/env python # -*- coding:utf-8 -*- import socket ip_port = ('127.0.0.1',9999 ...

  9. 04讲 正确使用heterogeneous类型的元件

    heterogeneous类型的元件1.可能出现的错误     再使用数个heterogeneous 元件的时候会因为分部件的不匹配 2.出现错误的原因原因是这四个运放,软件它并不识别那两个是配在一起 ...

  10. java多线程系类:JUC线程池:06之Callable和Future(转)

    概要 本章介绍线程池中的Callable和Future.Callable 和 Future 简介示例和源码分析(基于JDK1.7.0_40) 转载请注明出处:http://www.cnblogs.co ...