![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Python
绅士小浩
随着岁月的流逝,带来的是淡定从容。
展开
-
算法-Python2.7实现用数组看作堆来实现最优先队列(最大堆)
废话不多说,直接上代码# coding=UTF-8import numpy as npdef sift_down(parent): #向下调整 i = parent j = 2*i+1 tmp = npyArray[parent] while(j < len(npyArray)): if((j < ...原创 2019-04-11 21:12:41 · 243 阅读 · 0 评论 -
算法-Python2.7实现对比两个文件(document)相似度(cosine distance)
#coding=utf-8import stringimport mathdef get_word_count (file) : txt = open(file).read().lower() #打开文件读取内容,并且把大写字母转化为小写字母 for p in string.punctuation: txt = txt.replace(p ," ") ...原创 2019-04-12 17:14:13 · 1299 阅读 · 0 评论 -
Python2.7 把英文文档中的所有标点符号转为空格(或删除)
有时候做词频统计或者文档相似度时,首先我们需要过滤掉文件中的标点符号,然后根据空格来转化为一个个单词,以下我总结出两种方法:方法一: for p in string.punctuation: txt = txt.replace(p ," ")方法二:translation = string.maketrans(string.punctuation+string....原创 2019-04-12 17:21:25 · 8646 阅读 · 2 评论 -
算法-Python2.7实现平衡二叉树中序遍历(in-order traversal of the AVL tree)
# coding=UTF-8import numpy as npclass Node: def __init__(self): self.left_children = None self.left_height = 0 self.right_children = None self.right_height = 0 ...原创 2019-05-17 17:04:26 · 804 阅读 · 0 评论