python
文章平均质量分 60
000fly
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
python画图
#coding=utf-8import matplotlib.pyplot as pltimport numpy as npnonLeafNode=dict(boxstyle="sawtooth",fc="0.8") #非叶节点,箱子格式,和leafNodes=dict(boxstyle="round4",fc="0.8")line=dict(arrowstyle="<-")d原创 2017-03-20 16:14:14 · 1267 阅读 · 0 评论 -
快速排序
#coding=utf-8import mathimport randomdef swap(A,i,j): r=A[i] A[i]=A[j] A[j]=r def partition(A,p,r): x=A[r] i=p-1 for j in list(range(p,r)): if A[j]原创 2017-03-26 16:53:45 · 243 阅读 · 0 评论 -
计数排序
#coding=utf-8import mathimport randomdef swap(A,i,j): r=A[i] A[i]=A[j] A[j]=rdef getRandomList(n): i=0 lists=[] while i lists.append(random.randint原创 2017-03-26 17:56:49 · 276 阅读 · 0 评论 -
机器学习实战第二章,kNN
#coding=utf-8from numpy import *from os import listdirimport operatordef createDataSet(): #创建数据集 group=array([[1.0,1.1],[1.0,1.0],[0,0],[0,0.1]]) labels=['A','A','B','B'原创 2017-04-29 06:21:05 · 858 阅读 · 0 评论 -
python创建n行m列数组
>>> matrix=[None]*2>>> print(matrix)[None, None]>>> for i in range(len(matrix)): matrix[i ]=[0]*3>>> print(matrix)[[0, 0, 0], [0, 0, 0]]>>> 例n = 2 m = 3 matrix = [None]*2 f转载 2017-07-31 08:16:45 · 20311 阅读 · 0 评论 -
python排序,保留索引值
: 比如对a = [3,4,1,7,2]用a.sort()排序得到a = [1,2,3,4,7],请问如何得到排序后的: 数组元素的索引系列,是说,在原来数组中的索引。: : 在这个例子里应该是[2,4,0,1,3].: : 谢谢In [1]: a = [3,4,1,7,2]In [2]: enumerate(a)Out[2]: In [3]: list转载 2017-07-31 15:09:45 · 16128 阅读 · 1 评论 -
创建固定长度列表
>>> a=[[3,4,9],[1,3,4],[9,0,2]]>>> b=a[:2]>>> b[[3, 4, 9], [1, 3, 4]]>>> c=[None]*3>>> for i in range(len(c)): c[i]=[0]*3 >>> c[[0, 0, 0], [0, 0, 0], [0, 0, 0]]>>> c[0:1]=b[1:2]>原创 2017-07-31 15:18:39 · 2134 阅读 · 2 评论 -
python创建采样坐标点,可以为浮点数。
points=np.arange(-5,4.9,0.01)原创 2017-07-31 19:50:03 · 1195 阅读 · 0 评论 -
python基础篇日记
-----------------------------------------1,基础篇。#encoding=utf-8#上面可以随便写的,只要符合oding=[]#basic1.py //相当于导入了asic1模块 #可以使用 basic1.new_str#这里给下面语句做一个注释ne原创 2017-03-22 17:09:25 · 346 阅读 · 0 评论 -
python实现SMTP客户端
#!/usr/bin/python# -*- coding: UTF-8 -*- import smtplibfrom email.mime.text import MIMETextfrom email.header import Header # 第三方 SMTP 服务mail_host='smtp.163.com' #设置服务器mail_user='xxx@163.com'原创 2017-07-26 09:14:16 · 2141 阅读 · 0 评论 -
python访问复数的实部,虚部和模值
>>> a=4+5j 产生一个复数>>> a(4+5j)>>> a.real 复数的实部。.real4.0>>> a.imag 虚部5.0>>> abs(a) 模6.4031242374328485>>> c=complex(3,4) 产生一个复数>>> c(3+4j)>>>原创 2017-07-27 20:14:42 · 27061 阅读 · 1 评论 -
python剔除符合条件的元素,不如剔除0
a = [1, 2, 0, 3, 4, 0, 5, 0, 6]for b in a: if b == 0: a.remove(b)print a--------------------------------------a = [1, 2, 0, 3, 4, 0, 5, 0, 6]a = filter(lambda x: x > 0, a)原创 2017-07-27 20:21:00 · 3854 阅读 · 0 评论 -
python else用法
与多数编程语言一样,Python中同样也有else关键字但与多数编程语言不一样的是,else关键字在python中的用法不仅仅是普通的else下面通过简单的例子说明else的三个用法首先是最普通的,与if搭配的分支结构:[python] view plain copy print?num = int(input('请输入一个整数:')原创 2017-07-27 20:56:47 · 2161 阅读 · 0 评论 -
python 堆的操作
#coding=utf-8import mathimport randomdef getRandomList(n): i=0 lists=[] while i<n: lists.append(random.randint(1,100)) i+=1 return listsdef PARENT(i): re原创 2017-03-25 22:04:43 · 357 阅读 · 0 评论 -
python关键字
False class finally is returnNone continue for lambda tryTrue def from nonlocal whileand del global not withas原创 2017-04-02 10:51:19 · 464 阅读 · 0 评论 -
Python document-The python tutorial
28视频: 正则表达式常用函数: 35视频:>>> import os>>> g=os.walk("d:/test")>>> os.walk("d:/test") //产生一个walk对象的生成器。>>> for i in g:... print g... >>> ----------原创 2017-04-02 10:50:24 · 922 阅读 · 0 评论 -
subplot的用法
plt.subplot(1,4,2) #将图分为1行4列,选第二个子图plt.subplot(245) #将图分为2行4列选第5个子图。原创 2017-03-19 22:19:53 · 2373 阅读 · 0 评论 -
cart未实现
#coding=utf-8import csvimport numpy as npfrom numpy import *import pandas as pdfrom math import logimport operatorimport matplotlib.pyplot as pltfile=open("1.csv",'r')reader=csv.原创 2017-03-17 23:26:34 · 317 阅读 · 0 评论 -
sci文章下载
1进入图书馆 2, 3 4 5 6原创 2017-03-13 12:10:02 · 1480 阅读 · 0 评论 -
python求导
from sympy import *import symboldef fun(dic): sum='' for k,v in dic.items(): sum=sum+'+'+str(k)+'*'+'x'+'**'+str(v) return sum #expressiondic={'3':0,'4':1原创 2017-03-13 10:02:10 · 13176 阅读 · 0 评论 -
收藏
点击打开链接 numpy中argmin和argmax是使用转载 2017-03-04 22:08:20 · 297 阅读 · 0 评论 -
python安装之后,创建快捷方式
在开始菜单输入IDLE,将会出现python的GUI,添加到桌面即可。原创 2017-03-04 14:24:01 · 6708 阅读 · 0 评论 -
python类定义。
一、类定义:class : 类实例化后,可以使用其属性,实际上,创建一个类之后,可以通过类名访问其属性如果直接使用类名修改其属性,那么将直接影响到已经实例化的对象 类的私有属性:__private_attrs 两个下划线开头,声明该属性为私有,不能在类地外部被使用或直接访问在类内部的方法中使用时 self.__private_attrs 类的转载 2017-03-04 10:43:07 · 459 阅读 · 0 评论 -
python关键字
Python中的关键字包括如下:and del from not while as elif global or with assert else if pass yield break except import print class exec in raise continue finally is return def for lambda try你想看看有哪些关键字?转载 2017-02-27 16:28:31 · 363 阅读 · 0 评论 -
python插入排序算法
#coding=utf-8def sort(arr): for j in range(1,len(arr)): key=arr[j] i=j-1 while i>0 and arr[i]>key: arr[i+1]=arr[i] i=i-1 arr[i+原创 2017-03-20 18:52:28 · 328 阅读 · 0 评论 -
分治算法递归求最大子数组,下标,和
#coding=utf-8import mathdef getCroosMaxNum(arr,low,mid,high): lsum=-(math.inf) leftsum=0 a=list(range(low,mid)) a.reverse() b=a for i in b: leftsum=arr[i]+le原创 2017-03-21 23:29:05 · 473 阅读 · 0 评论 -
python递归分治求最大子数组失败
#coding=utf-8import mathdef getCroosMaxNum(arr,low,mid,high): lsum=-(math.inf) leftsum=0 a=list(range(low,mid)) a.reverse() b=a for i in b: leftsum=arr[i]+le原创 2017-03-22 12:23:01 · 451 阅读 · 0 评论 -
python多线程压缩文件
#coding utf-8import threadingimport zipfileclass Asynczip(threading.Thread): def __init__(self,infile,outfile): threading.Thread.__init__(self) self.infile=infile原创 2017-04-02 09:21:52 · 3943 阅读 · 1 评论 -
python找列表中最大值所在的位置
>>> b=[[3, 4, 5], [3, 4, -9], [5, 5, 3]]>>> np.amax(b) #找最大元素,可以防止使用max有多个最大值的情况5>>> c=np.where(b==np.max(b))>>> c(array([0, 2, 2], dtype=int32), array([2, 0, 1], dtype=int3原创 2017-07-28 11:00:02 · 19014 阅读 · 1 评论
分享