
Python和Cython
文章平均质量分 82
mmc2015
北大信科学院,关注深度强化学习。http://net.pku.edu.cn/~maohangyu/
展开
-
python的【列表list】:定义、索引、添加、删除、遍历、长度;组合、重复、反转、切片、比较;排序
序列是Python中最基本的数据结构。序列中的每个元素都分配一个索引,第一个索引是0,第二个索引是1,依此类推。列表的数据项不需要具有相同的类型;基本操作:创建列表,只要把逗号分隔的不同的数据项使用方括号括起来即可:指定特殊值初始化列表:组合、重复、反转、切片、比较:原创 2015-09-20 23:07:23 · 4443 阅读 · 0 评论 -
python中matplotlib的颜色及线条控制【以及改变legend字体大小】
转载请注明出处:http://www.cnblogs.com/darkknightzh/p/6117528.html参考网址:http://stackoverflow.com/questions/22408237/named-colors-in-matplotlibhttp://stackoverflow.com/questions/8409095/matplotl转载 2017-06-01 10:46:16 · 36541 阅读 · 0 评论 -
python二进制处理详述
from:https://www.kaggle.com/benhamner/d/uciml/iris/python-data-visualizations/notebookThis notebook demos Python data visualizations on the Iris datasetThis Python 3 environment转载 2015-08-22 22:24:13 · 2334 阅读 · 0 评论 -
cython,加速python,保护代码(2):Faster code via static typing
http://docs.cython.org/src/quickstart/cythonize.htmlCython is a Python compiler. This means that it can compile normal Python code without changes (with a few obvious exceptions of some as-yet原创 2016-07-15 15:06:16 · 2055 阅读 · 0 评论 -
Cython,加速python,保护代码(1):Overview
一个更完整的例子:http://docs.cython.org/src/tutorial/cython_tutorial.htmlPrimesHere’s a small example showing some of what can be done. It’s a routine for finding prime numbers. You tell it ho转载 2016-07-15 14:14:34 · 3731 阅读 · 0 评论 -
cython,加速python,保护代码(3):扩展文件 .pxd
.pxd文件相当于c语言中的头文件.h。Using an augmenting .pxd allows to let the original .py file completely untouched. On the other hand, one needs to maintain both the .pxd and the .py to keep them in转载 2016-07-15 15:18:37 · 4315 阅读 · 0 评论 -
python平行(3):【parallel python】与【sklearn joblib的parallel和delayed】性能对比
随机森林的并行写完了。大致采用了两种方法:1)一种是 python并行(1)中提到的joblib的parallel和delayed方法(具体实现是直接使用sklearn.externals.joblib,因为sklearn优化得很好)2)第二种是采用http://www.parallelpython.com/的SMP两者编程都很简单,但效率相差还是挺大的,这里大概贴出三者的编程原创 2016-07-11 09:47:07 · 18957 阅读 · 4 评论 -
python并行(2):python多进程与多线程
转自:http://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/00143192823818768cd506abbc94eb5916192364506fa5d000感谢廖老师。在Unix/Linux下,可以使用fork()调用实现多进程。要实现跨平台的多进程,转载 2016-07-10 20:28:45 · 4721 阅读 · 0 评论 -
python并行(1)
最近在看scikit learn的random forest源码,之后会公布一些简化版的代码,欢迎大家关注。【predict_proba】中有一块代码不清楚怎么回事。https://github.com/scikit-learn/scikit-learn/blob/51a765a/sklearn/ensemble/forest.py#L543# Parallel loo原创 2016-07-05 22:44:05 · 9199 阅读 · 1 评论 -
用C语言扩展Python的功能
https://www.ibm.com/developerworks/cn/linux/l-pythc/写的简单但非常清楚。Pyton和C分别有着各自的优缺点,用Python开发程序速度快,可靠性高,并且有许多现成模块可供使用,但执行速度相对较慢;C语言则正好相反,其执行速度快,但开发效率低。为了充分利用两种语言各自的优点,比较好的做法是用Python开发整转载 2016-05-30 16:05:13 · 591 阅读 · 0 评论 -
读写文件:每次读入大文件中的一行、读写.CSV文件
读文件:传统的读法,全部读出,按行处理:fp=open("./ps.txt", "r");alllines=fp.readlines();fp.close();for eachline in alllines: print eachline 推荐读取方法,使用文件迭代器 , 每次只读取和显示一行,读取大文件时应该这样:fp=open("./ps.txt",原创 2015-07-17 21:04:38 · 5179 阅读 · 0 评论 -
python的【字典dict】:创建、访问、更新、删除;查看键、值、键值对;遍历;排序
字典是另一种可变容器模型,且可存储任意类型对象。字典的每个键值(key=>value)对用冒号(:)分割,每个对之间用逗号(,)分割,整个字典包括在花括号({})中 ;字典值可以没有限制地取任何python对象,既可以是标准的对象,也可以是用户定义的;但键不行,如果同一个键被赋值两次,后一个值会被记住。值可以取任何数据类型,但键必须是不可变的,如字符串,数字或元组(列表原创 2016-03-02 09:46:38 · 29848 阅读 · 0 评论 -
python的【字符串string】:运算符、内建函数
Python字符串运算符下表实例变量a值为字符串"Hello",b变量值为"Python":操作符描述实例+字符串连接a + b 输出结果: HelloPython*重复输出字符串a*2 输出结果:HelloHello[]通过索引获取字符串中字符a[1] 输出原创 2015-08-23 22:48:32 · 1889 阅读 · 0 评论 -
python3练习
参考:http://www.runoob.com/python3/python3-tutorial.html输入:>>> a=input("input something:")input something:hello world>>> a'hello world'输出:加括号、不换行>>> print("Hello, Python!")Hello,原创 2018-01-15 21:25:46 · 840 阅读 · 0 评论