![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python
iamzhangzhuping
这个作者很懒,什么都没留下…
展开
-
python if __name__ == '__main__' 详解
转自:http://www.cnblogs.com/xuxm2007/archive/2010/08/04/1792463.html当你打开一个.py文件时,经常会在代码的最下面看到if __name__ == '__main__':,现在就来介 绍一下它的作用. 模块是对象,并且所有的模块都有一个内置属性 __name__。一个模块的 __name__ 的值取决于您转载 2015-10-13 20:32:30 · 515 阅读 · 0 评论 -
python核心模块pickle和cPickle
使用pickle模块你可以把Python对象直接保存到文件,而不需要把他们转化为字符串,也不用底层的文件访问操作把它们写入到一个二进制文件里。 pickle模块会创建一个python语言专用的二进制格式,你基本上不用考虑任何文件细节,它会帮你干净利落地完成读写独享操作,唯一需要的只是一个 合法的文件句柄。 pickle模块中的两个主要函数是dump()和load()。dump()函数接受一转载 2016-05-11 09:42:14 · 556 阅读 · 0 评论 -
python eval()
eval()函数十分强大,官方demo解释为:将字符串str当成有效的表达式来求值并返回计算结果,比较简单,这里就不做解释了,下面介绍一种比较少见的用途:定义一个类:class Myclass(object): def gt_roidb(self): print 'gt_roidb...'在解释器中输入:mc = Myclass()m = eval('mc.' + 'gt原创 2016-05-14 14:19:41 · 652 阅读 · 1 评论 -
Python 装饰器,@property 以及 Pycaffe.py
Python装饰器的知识请参考:12步轻松搞定python装饰器 @property函数的知识请参考:Python进阶之“属性(property)”详解下面贴一段pycaffe.py中的代码@propertydef _Net_blobs(self): """ An OrderedDict (bottom to top, i.e., input to output) of netw原创 2016-05-13 17:28:05 · 1756 阅读 · 0 评论 -
python tile
tile函数 在看机器学习实战这本书时,遇到numpy.tile(A,B)函数,愣是没看懂怎么回事,装了numpy模块后,实验了几把,原来是这样子:重复A,B次,这里的B可以时int类型也可以是远组类型。[python] view plain copy >>> import numpy >>> numpy.原创 2016-05-15 19:45:25 · 866 阅读 · 0 评论 -
numpy multiply
numpy.multiply(x1, x2[, out]) : Multiply arguments element-wise, 广播法则。numpy的multiply和*什么区别 Numpy matrices必须是2维的,但是numpy arrays (ndarrays) 可以是多维的(1D,2D,3D····ND). Matrix是Array的一个小的分支,包含于Array。所以mat原创 2016-08-29 22:25:15 · 1720 阅读 · 0 评论 -
numpy.flatten() 与 numpy.ravel()的区别
首先声明两者所要实现的功能是一致的(将多维数组降位一维),两者的区别在于返回拷贝(copy)还是返回视图(view),numpy.flatten()返回一份拷贝,对拷贝所做的修改不会影响(reflects)原始矩阵,而numpy.ravel()返回的是视图(view,也颇有几分C/C++引用reference的意味),会影响(reflects)原始矩阵。>>> x = np.array([[1, 2原创 2016-08-30 09:38:55 · 5940 阅读 · 0 评论 -
numpy * dot multiply
* 需要记住的是: numpy arrays consistently abide by the rule that operations are applied element-wise. Thus, if a and b are numpy arrays, then a*b is the array formed by multiplying the components element-wi原创 2016-08-30 16:06:06 · 3960 阅读 · 0 评论 -
pandas.DataFrame 操作
pandas.DataFrame 操作 这篇文章说的很好。 总结: DataFrame 有属性和索引的概念,属性即列,索引即行 DataFrame 取一列得到Series,取多列得到DataFrame(Pdb) type(data['Test 1'])原创 2016-08-30 21:25:23 · 4227 阅读 · 0 评论 -
python 贪婪与非贪婪模式
re.match(r"aa(\d+?)","aa2343ddd").group()Out[45]: 'aa2're.match(r"aa(\d+?)d","aa2343ddd").group()Out[46]: 'aa2343d're.match(r"aa(\d+?)d??","aa2343ddd").group()Out[43]: 'aa2're.match(r"aa(\d+?)d+",原创 2016-03-21 15:16:24 · 2001 阅读 · 0 评论 -
re.findall
re.findall(pattern, string, flags=0) Return all non-overlapping matches of pattern in string, as a list of strings. The string is scanned left-to-right, and matches are returned in the order found. If原创 2016-03-21 14:52:30 · 874 阅读 · 0 评论 -
matplotlib的配置参数rcParams
配置文件的读入可以使用 rc_params 函数,它返回一个配置字典: matplotlib.rc_params() {‘agg.path.chunksize’: 0, ‘axes.axisbelow’: False, ‘axes.edgecolor’: ‘k’, ‘axes.facecolor’: ‘w’,原创 2016-03-03 22:23:36 · 31043 阅读 · 0 评论 -
python print
看看《Python基础编程》中对格式化输出的总结:(1). %字符:标记转换说明符的开始(2). 转换标志:-表示左对齐;+表示在转换值之前要加上正负号;“”(空白字符)表示正数之前保留空格;0表示转换值若位数不够则用0填充(3). 最小字段宽度:转换后的字符串至少应该具有该值指定的宽度。如果是*,则宽度会从值元组中读出。(4). 点(.)后跟精度值:如果转换的是实数,精度值就表示出现在小数点后的位原创 2016-03-04 15:48:39 · 552 阅读 · 0 评论 -
numpy.reshape
numpy.reshape(a, newshape, order=’C’) 官方解释:Gives a new shape to an array without changing its data.看几个例子l=range(120)import numpy as nparr=np.array(l)arr=arr.reshape(2,4,5,3)arr为: [[[[ 0, 1,原创 2016-03-04 16:00:45 · 2450 阅读 · 0 评论 -
matplotlib.pyplot.imshow
官方:Display an image on the axes.注意这个参数XX : array_like, shape (n, m) or (n, m, 3) or (n, m, 4)Display the image in X to current axes. X may be a float array, a uint8 array or a PIL image. If X is an arr原创 2016-03-04 16:23:08 · 3440 阅读 · 0 评论 -
numpy.ndarray.flatten
numpy.ndarray.flattenndarray.flatten(order=’C’) Return a copy of the array collapsed into one dimension.Parameters: order : {‘C’, ‘F’, ‘A’}, optional Whether to flatten in row-major (C-style) or co原创 2016-03-05 10:04:11 · 647 阅读 · 0 评论 -
numpy.ndarray.flatten
官方: ndarray.flatten(order=’C’) Return a copy of the array collapsed into one dimension.Parameters: order : {‘C’, ‘F’, ‘A’}, optional Whether to flatten in row-major (C-style) or column-major (Fort原创 2016-03-05 14:20:37 · 927 阅读 · 0 评论 -
python处理.seq文件
# Deal with .seq format for video sequence# Author: Kaij# The .seq file is combined with images,# so I split the file into several images with the image prefix# "\xFF\xD8\xFF\xE0\x00\x10\x4A\x46\x4转载 2016-03-06 18:48:51 · 2964 阅读 · 1 评论 -
python os模块常用函数
下面列出了一些在Python os模块中比较有用的部分。它们中的大多数都简单明了。os.sep 可以取代操作系统特定的路径分割符。os.name字符串指示你正在使用的平台。比如对于Windows,它是’nt’,而对于Linux/Unix用户,它是’posix’。os.getcwd()函数得到当前工作目录,即当前Python脚本工作的目录路径。os.getenv()和os.putenv()函数分别用来原创 2016-03-06 21:48:36 · 1491 阅读 · 0 评论 -
常用的数据预处理操作
Normalization:向量的每个元素除以它的二范数(默认情况下) sklearn.preprocessing.normalize(X, norm=’l2’, axis=1, copy=True) X = [[ 1., -1., 2.], … [ 2., 0., 0.], … [ 0., 1.,原创 2016-08-11 18:01:30 · 1648 阅读 · 0 评论