02 2014 档案
摘要:http://blog.chinaunix.net/uid-26722078-id-3484197.html1.列表推导看几个例子,一切就明白了。 1 #!/usr/bin/python 2 numbers = range(10) 3 size = len(numbers) 4 evens = [] 5 i = 0 6 while i < size: 7 if i%2 == 0: 8 evens.append(i) 9 i += 110 print evens11 12 #!/usr/bin/python13 evens = [i for i in range...
阅读全文
摘要:http://eagletff.blog.163.com/blog/static/116350928201266111125832/一般情况下,如果要对一个列表或者数组既要遍历索引又要遍历元素时,可以用enumerate比如:for index,value in enumerate(list):print index,value当然也可以for i in range(0,len(list)):print i,list[i]相比较而言,前者更简练另外一种使用情况,当要计算文件的行数的时候,可以这样写:lineNum = len(open(fileName,'r').readlin
阅读全文
摘要:1 >>> help(set) 2 Help on class set in module __builtin__: 3 4 class set(object) 5 | set(iterable) --> set object 6 | 7 | Build an unordered collection of unique elements.#无序、独一无二的元素 8 | 9 | Methods defined here: 10 | 11 | __and__(...) 12 | x.__and__(y) x&y 13 | 14 | ...
阅读全文
摘要:转自:http://blog.csdn.net/business122/article/details/7536991 1 创建列表 2 sample_list = ['a',1,('a','b')] 3 4 Python 列表操作 5 sample_list = ['a','b',0,1,3] 6 7 得到列表中的某一个值 8 value_start = sample_list[0] 9 end_value = sample_list[-1] 10 11 删除列表的第一个值 12 del sample_list[
阅读全文
摘要:转自:http://blog.csdn.net/business122/article/details/7537014 1 一.创建字典 2 方法①: 3 >>> dict1 = {} 4 >>> dict2 = {'name': 'earth', 'port': 80} 5 >>> dict1, dict2 6 ({}, {'port': 80, 'name': 'earth'}) 7 8 方法②:从Python 2.2 版本起 9 >&
阅读全文
摘要:转自:http://blog.csdn.net/business122/article/details/7541486 1 python的set和其他语言类似, 是一个无序不重复元素集, 基本功能包括关系测试和消除重复元素. 集合对象还支持union(联合), intersection(交), difference(差)和sysmmetric difference(对称差集)等数学运算. 2 3 sets 支持 x in set, len(set),和 for x in set。作为一个无序的集合,sets不记录元素位置或者插入点。因此,sets不支持 indexing, slicin...
阅读全文
摘要:1 #统计词频,可以根据需要统计句子或文本 2 txt = 'this is a student there is a bag' 3 words = txt.split() 4 dict = {} 5 for w in words: 6 if w not in dict: 7 dict[w] = 1 8 else: 9 dict[w] = dict[w] + 110 print dict
阅读全文
摘要:1.决策树理解比较简单,关键要自己把理论用笔实践一遍,推荐http://www.cise.ufl.edu/~ddd/cap6635/Fall-97/Short-papers/2.htm教程。自己把里面的数据用matlab或python辅助计算下。2.信息增益(Information Gain)和 (熵Entropy)3.list 3-1计算给定数据集的香农熵for featVec in dataSet: currentLabel=featVec[-1] if currentLabel not in labelCounts.keys(): ...
阅读全文

浙公网安备 33010602011771号