
python
mathilde27
这个作者很懒,什么都没留下…
展开
-
python的 __getattr__自动构建generator
get attr原创 2022-12-16 10:15:56 · 196 阅读 · 0 评论 -
python与C的数据转换
py原创 2022-11-10 10:37:32 · 652 阅读 · 0 评论 -
一个简单的遗传算法
import numpy as npsize=10UPPER_BOUND=4LOWER_BOUND=0deviation=0.25num_offspring=3num_iter=30def check_bound(x): if x<LOWER_BOUND: return LOWER_BOUND if x>UPPER_BOUND: return UPPER_BOUND return xdef fitness(x): .原创 2020-10-21 16:22:38 · 291 阅读 · 0 评论 -
python技巧
数组操作::要取后面6个元素两两配对,涉及到数组操作::mother=[6,8,10]father=[5,7,9]根据排序删除元素保留前size个元素原创 2020-10-21 16:11:33 · 162 阅读 · 1 评论 -
python-numpy
1.sum a1, 2 | axis 13, 4 |--------| axis 0 a.sum(axis=0) array([4, 6]) a.sum(axis=1) array([3, 7])2. np.square 每个元素3. 加维度a=[1,2] aa=a[:,None] aa.shape=(2,1)b=[1,2,3] bb=b[原创 2017-09-29 15:09:41 · 583 阅读 · 0 评论 -
python安装dlib
不用cmake, c++源码编译,不用安装boost直接 https://pypi.python.org/pypi/dlib/18.17.100pip install dlibxxx.whl ( 18版本是 cp35的) ( 19 版本是cp36的)import dlibdetector=dlib.get_原创 2017-09-02 16:35:28 · 6188 阅读 · 6 评论 -
写python的扩展模块(C)
把C语言写的函数作为python的扩展模块。为python创建扩展需要三个步骤: 1. 创建程序代码(C) 2. 写包装代码 3. 编译(写setup.py进行build)下面先给出一个最简单的例子的: 计算一个数的二分之一,仅包含两个文件half.c 和setup.py。先给出这两个例子的全部代码,再详细讲解。这个例子参考了 c-info.ufunc-tutorialhalf.c#in原创 2017-05-27 08:10:29 · 700 阅读 · 0 评论 -
SQL入门
最近想做一个人脸相册,需要用到数据库。python内置有sqlite3,可以直接使用,不用安装。首先说一下数据库的几个基本概念:table(表)是数据库中存放数据的集合,一个数据库里面包含多张表,比如我要设计的数据库里面,包含image table, face table, person table。表和表之间用外键(foreign key)关联, 比如在我的例子中,外键是: image_id,原创 2017-05-24 11:15:06 · 449 阅读 · 0 评论 -
文章标题
os.path.splitext# (root, ext) 文件名,后缀名root,ext=os.path.splitext("H:/home/image.jpg")ext="jpg"os.path.split# (head, tail) 根路径 文件名head,tail=os.path.splitext("H:/home/image.jpg")head="H:/home"tail="im原创 2017-03-24 09:07:50 · 367 阅读 · 0 评论 -
pythonic code(1)
dict.setdefault(key,default)“listcomps”: List comprehensions provide a concise way to create lists.Testing for Ture Values(http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#id33)原创 2017-03-07 11:08:35 · 497 阅读 · 0 评论 -
caffe python常用语句
添加caffe路径import syscaffe_root = '/home/lcy/caffe-master/' sys.path.insert(0, caffe_root + 'python')import caffe设置CPU|GPUCPU:caffe.set_mode_cpu()GPU:caffe.set_mode_gpu()加载模型modelmodel_def = 'deploy.p原创 2017-02-15 11:48:15 · 902 阅读 · 0 评论 -
pyuthon高级技巧2
list or dict 在需要重复查找的时候,dicty用hash表示实现,复杂度为O(1),list的复杂度为O(n)data_list=['a','b','is','python','jason','hello','hill','with','phone','test', 'dfdf','apple','pddf','ind','basic','none','baecr','var','原创 2017-01-19 10:16:23 · 670 阅读 · 0 评论 -
matplotlib常用命令
import matplotlib.pyplot as pltimport numpy as npx=np.linspace(-10,10,500)plt.plot(x, y, 'g', label='myfunction')plt.ylim(-0.2, 0.4)plt.legend(loc='lower right', prop={'size': 11})set axis rangepl原创 2017-02-16 13:29:30 · 1033 阅读 · 0 评论 -
python的一些高级用法积累
for i,xx in emumerate(X)classes=['dog','cat','fish']for i,cls in enumerate(classes): i=0,1,2 cls='dog','cat','fish'这个比直接用for要快,下面看看例子:x=np.linspace(1,1e5,1e7)@timedef forf(x): for i in r原创 2016-12-07 21:02:45 · 4083 阅读 · 0 评论 -
python hash
首先讲 digest 这个词,小时候读的《读者文摘》叫 Readers Digest digest 作动词是消化、吸收的意思,名词是文摘、摘要、精华的意思。理解一下,只有消化吸收了才能总结归纳出摘要。Python的hashlib提供了常见的摘要算法,如MD5,SHA1等等。 摘要算法又称哈希算法、散列算法。它通过一个函数f,把任意长度的数据data(任意长度的文章)转换为一个长度固定的摘要(di原创 2016-12-01 13:20:32 · 513 阅读 · 0 评论 -
python pickle
save datapickle_file="dataset.pickle"try: f=open(pickle_file,"wb") save={"train_dataset":train_dataset, "train_labels":train_labels, "validate_dataset":validate_dataset,原创 2016-12-01 11:38:37 · 790 阅读 · 0 评论 -
python小笔记(未完待续)
解压序列(tuple,list, str) 个数要对应*星号解压,不确定长度first,*middle,last=grade*before,current=recordsdata=[1,2,3,-1]*x,y=data>>>x=[1,2,3]>>>y=-1最大,最小的N个元素 heap堆 queue 队列 heapqimport heapqa=[1,8,2,34,7,-4,原创 2016-11-04 14:15:20 · 377 阅读 · 0 评论