python
文章平均质量分 54
chilitian
这个作者很懒,什么都没留下…
展开
-
python 常用的正则表达式处理函数
常用的功能函数包括:match、search、findall、sub1、re.match()函数函数语法:re.match(pattern, string, flags=0)1 def match(pattern, string, flags=0):2 """Try to apply the pattern at the start of the string, returnin...转载 2018-11-22 14:02:33 · 360 阅读 · 0 评论 -
python 替换字符串的方法replace()、正则re.sub()
一、replace()函数1用字符串本身的replace方法:a = 'hello word'b = a.replace('word','python')print b二、re.sub()import rea = 'hello word'strinfo = re.compile('word')b = strinfo.sub('python',a)print b...转载 2018-11-22 14:08:20 · 7948 阅读 · 0 评论 -
python中有关json的4个函数 json.dumps()和json.loads() json.dump()和json.load()
一、json.dumps()函数的使用,将字典转化为字符串1 import json4 dict1 = {"age": "12"}5 json_info = json.dumps(dict1)6 print("dict1的类型:"+str(type(dict1)))7 print("通过json.dumps()函数处理:")8 print("json_info的类型:"+str(typ...转载 2018-11-27 18:53:04 · 144 阅读 · 0 评论 -
python 中 eval()函数的作用
eval函数就是实现list、dict、tuple与str之间的转化str函数把list,dict,tuple转为为字符串eval(a)str(b)原创 2018-11-27 19:42:08 · 1052 阅读 · 0 评论 -
python 去掉字符串中的空格以及换行符 replace() 的用法
str.replace(old, new[, max])old -- 将被替换的子字符串。new -- 新字符串,用于替换old子字符串。max -- 可选字符串, 替换不超过 max 次原创 2018-11-27 21:42:45 · 5009 阅读 · 0 评论 -
Numpy教程(三)
1、迭代数组2、数组操作reshape()修改数组形状import numpy as np a = np.arange(8)print (a)print ('\n')b = a.reshape(4,2)print (b)原始数组:[0 1 2 3 4 5 6 7]修改后的数组:[[0 1] [2 3] [4 5] [6 7]]翻转数组numpy....原创 2018-12-12 20:26:29 · 129 阅读 · 0 评论 -
machine learning Knn算法 最邻近规则取样(三)自己实现算法
import csv import randomimport mathimport operator#导入数据集,split将数据分为两部分,训练集和测试集def loadDataset(filename,split,trainingSet=[],testSet=[]): with open(filename,'rt') as csvfile: lines=csv.reader(...原创 2018-12-09 16:28:58 · 347 阅读 · 0 评论 -
机器学习python 支持向量机Support vectors machine (SVM算法)(线性可区分类一)
1、背景1.1最早有VNV和Alexey Ya C在1963年提出1.2目前的版本是由Cor和VNV在1993年提出,并在1995年发表1.3深度学习在2012年出现之前,SVM被认为机器学习近十几年来最成功,表现最好的算法2、机器学习的一般框架:训练集—>提取特征向量—>结合一定的算法(分类器:比如决策树和KNN)—>得到结果3、SVM介绍3.2SVM寻找区分两类...原创 2018-12-09 21:29:16 · 451 阅读 · 0 评论 -
创建Django项目
1、django-admin startproject test1manage.py:一个命令行工具,可以使用你多种方式对Django项目进行交互内层的目录:项目真正的Python包init.py:一个空文件,他告诉python这个目录应该被看作一个python包setting.py:项目的配置urls.py:项目的url声明wsgi.py:项目于wsgi兼容的web服务器入口...原创 2019-01-12 17:41:23 · 134 阅读 · 0 评论