python
文章平均质量分 79
pmt123456
这个作者很懒,什么都没留下…
展开
-
python小积累
Reverse-it#读取文件,逆转,然后保存成图片#注意hex和str的转换#字符串逆转的3种方法https://www.cnblogs.com/fengff/p/10367136.htmlif __name__ == '__main__': filename = "C:/Users/Administrator/Desktop/tmp/0da9641b7aad4efb8f7eb45f47eaebb2" file = open(filename, 'rb') str =原创 2020-10-19 16:42:03 · 173 阅读 · 0 评论 -
extend和append区别
转自 python: extend (扩展) 与 append (追加) 的差别>>> li = ['a', 'b', 'c'] >>> li.extend(['d', 'e', 'f']) >>> li ['a', 'b', 'c', 'd', 'e', 'f'] >>> len(li) 6 >>> li[-1]转载 2016-05-07 18:56:56 · 807 阅读 · 0 评论 -
theano tutorial(十)Graph Structures
Theano中将数学计算的工程用graph来进行表示。这些graph有一些内部节点构成:Apply,Variable和Op。Apply代表来将一些op应用于variables。注意区分用op表示的数学定义式和用实际的data来进行运算的实例(Application node) 。数据的类型使用Type实力来进行表示的。import theano.tensor as Tx = T.dmatr翻译 2016-04-20 13:09:41 · 622 阅读 · 0 评论 -
theano tutorial(九)Configuration Settings and Compiling Modes(译)
Configuration config 模块包含了几个属性用于修改Theano的行为,其中许多性质在导入Theano模块的时候就进行来检查,还有一些是只读的 我们规定,用户代码不能用于修改config里面的属性 Theano的代码给这些属性赋予来默认值,但是你可以在,theanorc文件里面重写这些属性,也可以依次用 THEANO_FLAGS 的环境变量重写这翻译 2016-04-19 21:19:23 · 537 阅读 · 0 评论 -
theano tutorial(六)Loop
Scan1.reduction 和 map 是 scan 的特例2.scan一个输入序列,每一个step输出一个output3.sum()可以通过对整个函数进行z+x(i)操作,z的初值为04.scan是theano对looping的封装5.使用scan的优势: 迭代此时可以成为symbolic graph的一部分 减少GPU的转换次数原创 2016-04-19 12:08:45 · 550 阅读 · 0 评论 -
theano tutorial(七)稀疏矩阵
theano支持两种稀疏矩阵:csc,csr,分别是按照列和行对数据进行存储的。每个稀疏矩阵都有data,indices,indptr和shape四个属性。data属性:一维ndarray,包含所有非零元素indices和indptr属性是用来存储稀疏矩阵中数据所在的位置shape属性与密集矩阵的shape属性是一致的,如果稀疏矩阵的形状不能从前三个属性推断出来的话,需要在创建的时候就原创 2016-04-19 16:40:24 · 725 阅读 · 0 评论 -
theano tutorial(六)IfElse vs Switch
1.IfElse 和 Switch都用于判定公式是否满足某种条件2.IfElse用boolean作为条件,输入为两个变量3.Swich用tensor作为条件,输入也为两个变量,Switch是一种elementwise操作符,因此比ifelse更加通用4.switch对每个输出变量进行操作,ifelse只对一个满足条件的变量操作#coding=utf-8# IfElse vs S原创 2016-04-19 11:35:54 · 1301 阅读 · 0 评论 -
theano tutorial(五)计算偏导数
#梯度计算import numpyimport theanoimport theano.tensor as Tfrom theano import ppx=T.scalar('x')y=x**2gy=T.grad(y,x)print(pp(gy))#pp()打印梯度的符号表达式#((fill((x ** TensorConstant{2}), TensorConstant{1.原创 2016-04-18 20:23:00 · 783 阅读 · 0 评论 -
theano tutorial(三)
theano的图结构,参见这篇文章ycheng_sjtu: Theano学习笔记(三)——图结构#coding=utf-8"""在theano graphs之间复制随机状态1.在两个图之间转换随机发生器的所有状态,(eg.用第一个graph里面发生器的状态去初始化第二个发生器里面图)2.theano.tensor.shared_randomstreams.RandomStreams原创 2016-04-18 17:16:26 · 626 阅读 · 0 评论 -
theano tutorial(四) logistic regression 练习
#coding=utf-8import numpyimport theanoimport theano.tensor as Trng=numpy.randomN=400#400类feats=784#784个特征#创建一个数据集D=(inputs_values,target_class)#randn:Return a sample (or samples) from the "s原创 2016-04-18 19:28:02 · 457 阅读 · 0 评论 -
theano tutotial(二)
#coding=utf-8"""1.对每一个随机数变量实际是分配了一个Numpy的RandomStream对象2.随机数流,伪随机数3.本质是shared变量4.seed设置来随机数发生器的起点,state是当前的状态"""#以下都是公仔在cpu上的from theano.tensor.shared_randomstreams import RandomStreamsfrom原创 2016-04-18 15:44:17 · 437 阅读 · 0 评论 -
theano tutorial(一)
#coding=utf-8"""shared使用共享变量shared函数创建共享变量可以被多个函数共享share函数可以用于符号表达式(例如=datrices返回的对象)alue可以通过.get_value和.set_value获得和修改updatesfunction.updates 其参数(shared-variable, new expression)是一个字典key:sh原创 2016-04-18 12:05:05 · 472 阅读 · 0 评论