自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(30)
  • 资源 (1)
  • 收藏
  • 关注

原创 逻辑回归实现信用卡欺诈检测

数据地址: https://www.kaggle.com/mlg-ulb/creditcardfraud#creditcard.csv代码地址:https://github.com/create-info/ML_DL_resources/blob/master/creditcard.ipynb

2019-09-19 12:48:44 219

原创 python读取csv文件

import csv# python读取csv文件:两种方式headers = ["username", "age", "height"]values1 = [ ('张三', 18, 180), ('李四', 19, 190), ('王五', 20, 178) ]values2 = [ {'username':'张三', 'age':18, 'hei...

2019-09-15 11:00:48 256 1

原创 python实现二叉树的遍历

# 二叉树的广度优先遍历class Node(object): def __init__(self, item): self.elem = item self.lchild = None self.rchild = Noneclass Tree(object): # 二叉树 def __init__(self): self.root = None...

2019-09-14 22:32:52 68

原创 python实现选择排序

def select_sort(list): n = len(list) for i in range(n-1): # i的取值为0~n-2之间 min_index = i for j in range(i+1, n): # j的取值为0~n-1之间 if list[i] > list[j]: min_index = j ...

2019-09-14 17:09:18 143

原创 python实现希尔排序

# 希尔排序def shell_sort(list): n = len(list) gap = n // 2 while gap >= 1: for j in range(gap, n): # j的取值为j+1,j+2,...,n-1 i = j while i > 0: if list[i] < lis...

2019-09-14 15:09:52 73

原创 python实现冒泡排序

# 冒泡排序def bubble_sort(list): n = len(list) - 1 for i in range(n): for j in range(0,n-i): if list[j] > list[j+1]: list[j], list[j+1] = list[j+1], list[j] j += 1if ...

2019-09-14 12:21:04 124

原创 python实现快速排序

def quick_sort(array, l, r): if l < r: q = partition(array, l, r) print(q) quick_sort(array, l, q - 1) quick_sort(array, q + 1, r) def partition(array, l, r):...

2019-09-13 23:55:34 83

原创 python实现归并排序

# 归并排序def merge_sort(list): n = len(list) # 先将待排序的数拆开 if n <= 1: # 拆分到只有一个元素为止,返回。 return list mid = n // 2 # print(list[:mid]) # print(list[mid:]) left_li = merge_sort(list...

2019-09-13 17:45:26 65

原创 python实现二分查找

def binarySearch(list, item): if len(list) < 0: return high = len(list) - 1 low = 0 min = int((low + high)/2) while(min <= high): if(list[min] == item): return min e...

2019-09-13 13:52:42 104

原创 python实现插入排序

# 插入排序算法实现def insert_sort(slist): size = len(slist) for i in range(1, size): # i从1开始 j = i while(j > 0): if slist[j-1] > slist[j]: slist[j-1], slist[j] = slist[j], s...

2019-09-11 00:32:00 87

原创 python实现双端队列

# coding=utf-8# 双端队列(允许两端都可以插入,删除)的实现class Deque(object): def __init__(self): self.list = [] # 从队列头部添加元素 def add_front(self, item): # self.list.push(item) # O(n) self.list.inse...

2019-09-09 01:26:21 316

原创 python实现队列

# coding=utf-8# 队列(只允许在一端插入,另一端删除)的实现class queue(object): def __init__(self): self.list = [] # 入队列 def enqueue(self, item): self.list.append(item) # O(1) # 出队列 def dequeue(sel...

2019-09-09 01:15:46 114

原创 python实现栈

# coding=utf-8# 可以使用顺序表(列表)或者链表实现栈class stack(object): # 栈的实现 def __init__(self): self.list = [] # 往栈顶(列表的尾部,因为插入元素时间复杂度低 # 如果使用链表,则使用链表的头部作为栈顶) # 添加元素 def push(self, item): s...

2019-09-09 00:58:46 73

原创 python实现双向链表的基本操作

# 双向链接的节点定义class Node(object): def __init__(self, item): self.elem = item self.next = None self.prev = Noneclass DoubleLinklist(object): # 双向链表 def __init__(self, node=None): ...

2019-09-08 18:44:57 292

原创 python实现单向循环链表的基本操作

# 单向循环链接的节点定义class Node(object): def __init__(self, item): self.elem = item self.next = Noneclass SingleCircularLinkList(object): """单向循环链表,与单链表相比,多了个尾节点指向头结点""" def __init__(self, n...

2019-09-08 15:11:43 518

原创 python单链表的操作

# 单向链表的节点定义class Node(object): def __init__(self, item): self.elem = item self.next = Noneclass SingleLinkList(object): """单向链表的基本操作""" def __init__(self, node=None): self.__he...

2019-09-08 13:40:34 210

原创 python对列表操作的时间效率

# python对列表操作的时间效率from timeit import Timer # timeit模块可以用来测试一小段Python代码的执行速度# 测试往空列表中存放数据的耗时def test1(): li = [] for i in range(10000): li.append(i)# 测试拼接列表的耗时def test2(): li = []...

2019-09-05 23:24:09 807

原创 使用协程下载图片

import urllib.requestimport geventfrom gevent import monkeymonkey.patch_all()def download(name, url): obj = urllib.request.urlopen(url) content = obj.read() with open(name, "wb") as f: ...

2019-09-05 22:27:42 361

原创 使用greenlet、gevent完成多任务

#--coding=utf-8--# greenlet对yeild进行了封装,不再需要自己手动在程序中出现yeildfrom greenlet import greenletimport timedef task_1(): while True: print("--------1-------------") g2.switch() time.sleep...

2019-09-05 21:33:23 102

原创 使用yield完成多任务

#--coding=utf-8--import timedef task_1(): while True: print("--------1-------------") time.sleep(0.1) yielddef task_2(): while True: print("--------2-------------") tim...

2019-09-05 20:23:44 166

原创 python生成器

#--coding=utf-8--#生成器实现斐波那契数列def num(Num): print("---------------1--------------------") a, b = 0, 1 cur = 0 while cur < Num: #print(a) print("---------------2------------------...

2019-09-04 23:39:32 131

原创 通过继承thread类完成创键线程

#--coding=utf8--import threadingimport timeclass MyThread(threading.Thread): def run(self): for i in range(3): time.sleep(1) msg = "我是" + self.name +' @' + str(i) # name属性是当期...

2019-09-04 00:18:01 102

原创 通过队列完成多进程之间的通信

#--coding=utf-8--import multiprocessing# 下载数据def download_from_web(q): # 模型从网上下载的数据 data = [11,22,33,44] # 向队列中写入数据 for temp in data: q.put(temp) print("------下载器已经下载完了数据并且存入到...

2019-09-04 00:17:19 200

原创 进程池

#--coding=utf-8--from multiprocessing import Poolimport os,time,randomdef worker(msg): start_time = time.time() print("%s 开始执行,进程号为%d" % (msg, os.getpid())) time.sleep(random.random()*2) ...

2019-09-04 00:16:25 61

原创 所任务udp聊天器

#--coding=utf8--import socketimport threading# 双工socket,每个端2个线程,一个收一个发# 接收信息def recv_msg(udp_socket): while True: rec_data= udp_socket.recvfrom(1024) print(rec_data)# 发送数据def send...

2019-09-04 00:14:47 64

原创 多进程

#--coding=utf8--import threadingimport multiprocessingimport timedef test1(): while True: print("--------------------- 1 ---------------------------") time.sleep(1)def test2(): w...

2019-09-04 00:05:51 49

原创 多任务文件夹复制

# --coding=utf-8--import osimport multiprocessingdef main(): # 1.获取用户要copy的文件夹的名字 old_folder_name = raw_input("请输入要copy的文件夹的名字: ") # 2.创建一个新的文件夹,获取try: except: pass,出现文件夹已存在则啥也不干 #if ...

2019-09-04 00:04:57 102

原创 单线程_多线程

#--coding=utf-8--import threadingimport timeimport testdef sing(): print("唱歌")# yyp用于复制一行 for i in range(5): #print("yyp复制唱歌") time.sleep(1)def dance(): for i in range(5): ...

2019-09-04 00:03:48 67

原创 使用互斥锁解决资源竞争问题

#--coding=utf8--import threadingimport time#定义一个全局变量g_num = 0def test1(num): global g_num #上锁,如果之前没有被上锁,则上锁成功,否则,会阻塞知道锁被释放为止 mutex.acquire() for i in range(num): g_num += 1 ...

2019-09-04 00:02:24 279

原创 python迭代器

#--coding=utf-8--import timefrom collections import Iterable # 判断是不是可以迭代,用Iterablefrom collections import Iterator # 判断是不是迭代器,用Iteratorclass Classmate(object): def __init__(self): se...

2019-09-03 23:54:42 61

机器学习K-近邻算法

k-近邻算法的Python实现

2016-09-28

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除