
python与人工睿智
lsh呵呵(平台已弃用)
https://github.com/lsh1994
展开
-
python杨辉三角
实现效果[1][1, 1][1, 2, 1][1, 3, 3, 1][1, 4, 6, 4, 1][1, 5, 10, 10, 5, 1][1, 6, 15, 20, 15, 6, 1][1, 7, 21, 35, 35, 21, 7, 1][1, 8, 28, 56, 70, 56, 28, 8, 1][1, 9, 36, 84, 126, 126, 84, 36, 9, 1]P原创 2017-04-20 23:22:48 · 536 阅读 · 0 评论 -
python读取csv文件
csv是逗号分隔值(Comma-Separated Values)的简称,见名知意,本质属于文本文件,(以“.csv”结尾)可以用Excel打开,详尽数据格式自行谷歌。样本数据使用iris,获取方式参考:http://blog.youkuaiyun.com/nima1994/article/details/72784545 方式一(适合直接是数据信息):import csvwith open("D:/iri原创 2017-05-27 23:11:56 · 1814 阅读 · 0 评论 -
python爬虫练习2
难度 ★ 目标网站 http://quotes.toscrape.com/tag/humor/ 用到库 scrapy1.4 系统说明 python3.6.1 64位 目标 获取名言与作者等(分页) 新建文件quotes_spider.py,输入一下代码:import scrapyclass QuotesSpider(scrapy.Spider): na原创 2017-07-14 10:49:24 · 711 阅读 · 0 评论 -
python爬虫练习1
目标网站 http://html-color-codes.info/color-names/ 用到库 requests,beautifulsoup4,lxml 系统说明 python3.6.1 64位 目标 获取颜色与颜色值等import requestsfrom bs4 import BeautifulSouphdrs={'User-Agent':'Mozilla/原创 2017-07-11 17:55:47 · 1008 阅读 · 0 评论 -
python爬虫练习3
说明获取豆瓣电影推荐页电影详情,参考网址https://movie.douban.com/explore#!type=movie&tag=%E7%83%AD%E9%97%A8&sort=recommend&page_limit=20&page_start=0 使用第三方库BeautifulSoup4,xlwt,lxml。代码import osimport jsonimport shutilf原创 2017-07-16 13:25:32 · 664 阅读 · 0 评论 -
Scrapy安装错误:Microsoft Visual C++ 14.0 is required...
问题描述当前环境win10,python_3.6.1,64位。 在windows下,在dos中运行pip install Scrapy报错:building 'twisted.test.raiser' extensionerror: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Too原创 2017-07-10 17:20:17 · 58293 阅读 · 49 评论 -
python爬虫练习5:博客阅读量助手
目标与环境爬取csdn博客如“http://blog.youkuaiyun.com/nima1994”的文章列表,获取阅读量等,与上次进行比较 使用eclipse+pydev编写,win10 64位,python 3.6.2;用到requests,beautifulsoup4,pandas等库。代码'''Created on 2017年9月30日@author: Harry'''i...原创 2017-10-03 18:26:47 · 652 阅读 · 0 评论 -
python print省略号
问题print的东西比较多,然后就以省略号(…)代替了解决方法(该包基于numpy?)import numpy as npnp.set_printoptions(threshold=np.inf)原创 2017-12-09 20:51:17 · 7703 阅读 · 1 评论 -
ValueError: Masked arrays must be 1-D
问题说明使用numpy画散点图出现以上问题。原代码如下:import numpy as npimport matplotlib.pyplot as pltdataSet=np.random.rand(2,10)dataSet=np.mat(dataSet)#1print(dataSet)plt.scatter(dataSet[0],dataSet[1])#2plt.show()解决方案方法很原创 2017-12-06 09:59:17 · 15666 阅读 · 1 评论 -
selenium淘宝的搜索按钮获取不到?
问题描述使用selenium做爬虫,模拟搜索框点击发起搜索时,发现淘宝的搜索框选不中,下面为代码:bt_submit=wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#J_SearchForm > button")))#方式1bt_submit=browser.find_element_by_css_selector("#原创 2018-01-18 18:01:29 · 1894 阅读 · 0 评论 -
python爬虫练习6:今日头条搜索图集
描述根据关键词下载图集等。结果如图: 代码import requestsfrom urllib.parse import urlencodeimport jsonimport osfrom hashlib import md5from multiprocessing import Pooldef get_page_index(offset,keyword原创 2018-01-19 12:18:57 · 1282 阅读 · 0 评论 -
RuntimeError: cannot release un-acquired lock
解决方案在导入其他包之前:from gevent import monkeymonkey.patch_all()原创 2018-04-03 09:59:03 · 9320 阅读 · 4 评论 -
TypeError: 'zip' object is not subscriptable
原代码:for dog,cat in zip(dp.dogs,dp.cats)[:1000]: #省略代码报错:TypeError: 'zip' object is not subscriptable解决方法:使用list包装zip对象,如下,for dog,cat in list(zip(dp.dogs,dp.cats))[:1000]: #省略代码...原创 2018-04-11 12:57:24 · 16795 阅读 · 0 评论 -
matplotlib显示中文
在显示中文之前加入代码:plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签plt.rcParams['axes.unicode_minus']=False #用来正常显示负号原创 2018-04-04 09:29:49 · 307 阅读 · 0 评论 -
python切片数组越界?
1 .在对list进行切片时,如x[9:12],若len(x)=10,只会返回x[9],而不会像其他语言直接数组越界错误。x=[i for i in range(10)]print(x)for i in range(0,10,3): print(x[i:i+3]) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] [0, 1, 2] [3, 4,...原创 2018-04-18 08:56:10 · 3300 阅读 · 0 评论 -
泰坦尼克号生存预测(上)-数据分析和预处理
数据来源:kaggle,Titanic: Machine Learning from Disaster你也可以通过nbviewer.jupyter直接访问。数据预处理主要包括:缺失数据处理数值特征归一化标签特征展开数据处理后如下表: ...原创 2018-04-26 19:10:09 · 2182 阅读 · 0 评论 -
机器学习数据集获取
加州大学欧文分校(UC Irvine)数据集网址:http://archive.ics.uci.edu/ml/ 本文以鸢尾花iris数据集为例:http://archive.ics.uci.edu/ml/datasets/Iris。 (进入http://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data后右键另原创 2017-05-27 21:50:19 · 2091 阅读 · 0 评论 -
python的KNN算法基本实现
数据集获取参考:http://blog.youkuaiyun.com/nima1994/article/details/72784545 关键步骤如下: 1.数据处理 通常数据集划分为训练集:测试集=67:33 2.相似度度量 欧氏距离:对字符串而言,即相同地位的元素不同个数 汉明距离:空间中的实际距离 3.近邻查找 4.预测结果 5.测试 代码如下:import csvimport原创 2017-05-28 15:38:27 · 615 阅读 · 0 评论 -
tensorflow安装:“ModuleNotFoundError: No module named '_pywrap_tensorflow_internal'”
问题描述初次安装tensorflow,win10x64位,python3.6.2 运行官网代码:import tensorflow as tfhello = tf.constant('Hello, TensorFlow!')sess = tf.Session()print(sess.run(hello))报错如下: 解决方案swig是一个python到c/c++的依赖包,该错误应该是缺少依原创 2017-09-24 15:36:19 · 13466 阅读 · 1 评论 -
python的开源微信接口
开源微信接口文档地址:https://itchat.readthedocs.io/zh/latest/ github地址:https://github.com/littlecodersh/itchat如下举例:import itchatitchat.auto_login()itchat.send('Hello,Test.无需回复.',toUserName=itchat.search...原创 2018-05-22 15:02:43 · 5287 阅读 · 1 评论 -
python获取文件夹、文件大小&hiberfil.sys
跑了个很简单的程序,c盘突然爆炸增加,顿时120G的盘只剩下几个G,所以有需求看看那些文件占用了大量空间。(事先通过360大文件扫描、日期排序分析未发现异常)import osimport sysdef getFileSize(filePath, size=0): if os.path.isfile(filePath):#文件 return os.path.get...原创 2018-06-02 21:10:59 · 1216 阅读 · 1 评论 -
二维数组叠加:channels_first与channels_last互转
在表示一组彩色图片的问题上,Theano和Caffe使用(样本数,通道数,行或称为高,列或称为宽)通道在前的方式,称为channels_first;而TensorFlow使用(样本数,行或称为高,列或称为宽,通道数)通道在后的方式,称为channels_last。如下构造二维矩阵以描述这种特殊的叠加方式(二种方法)。实现效果[[['1' '2'] ['3' '4']] [['5...原创 2018-05-16 10:56:41 · 5476 阅读 · 1 评论 -
python遇到IndexError: only integers, slices (`:`), ellipsis (`...`)……
完整错误信息如下: IndexError: only integers, slices (:), ellipsis (...), numpy.newaxis (None) and integer or boolean arrays are valid indices经检查,错误之处在索引处使用了浮点数,修改后部分代码如下:h=int(h) #修改成整型w=int(w) #修改成...原创 2018-06-13 08:53:08 · 78087 阅读 · 12 评论 -
python的赋值、浅拷贝和深拷贝
[原文链接](http://www.runoob.com/w3cnote/python-understanding-dict-copy-shallow-or-deep.html) 直接赋值:其实就是对象的引用(别名)。浅拷贝(copy):拷贝父对象,不会拷贝对象的内部的子对象。深拷贝(deepcopy): copy...转载 2018-06-17 13:18:47 · 230 阅读 · 0 评论 -
numpy的tile函数
在《机器学习实战》描述k近邻算法(p.19)时,用到了tile函数。numpy.tile(A, reps),其含义是对输入A 分别在各维度上进行reps.__iter__().__next__()次复制。比如:import numpy as nps=np.tile([1,2,3],(2,3))#第一维(行)复制2次,第二维(列)复制3次print(s) [[1 2 3 1 ...原创 2018-06-17 13:43:12 · 221 阅读 · 0 评论 -
flask的自定义bootstrap模板
由于flask-bootstrap的base.html模板提供功能有限(文件位置:/site-packages/flask_bootstrap/templates/bootstrap/base.html),比如我想在body中最后部分加上版权声明等。于是重新自定义一个Jinja2模板如下。结构结果代码base.html<!doctype html><...原创 2018-06-19 11:17:06 · 2735 阅读 · 0 评论 -
python if中的false(哪些视为False)
标题不太合适,即表示if判断为假的情况,具体如下。在Python中所有的对象都可以进行真值测试,下面罗列一下判断为假的情况:NoneFalse数值中的零,包括0,0.0,0j(虚数)空序列,包括空字符串(”),空元组(()),空列表([])空的字典{}自定义的对象的实例,该对象的__bool__方法返回False或者__len__方法返回0除了以上的情况外,所有的对象在if或...原创 2018-12-01 07:43:29 · 12291 阅读 · 0 评论