![](https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python
xiaoxy97
这个作者很懒,什么都没留下…
展开
-
Matplotlib小技巧
案例一小技巧:1、曲线上两点连线2、曲线上两点标注3、坐标轴范围设置import numpy as npimport matplotlib.pyplot as pltif __name__ == '__main__': x = np.arange(0, 3.01, 0.01) y = np.log(x) plt.plot(x, y, 'r-', lw=3, label=...原创 2018-06-26 23:09:32 · 544 阅读 · 0 评论 -
计数器
输入:from collections import Countercounter = Counter()for word in ['我', '是', '中国', '人', '我', '爱', '中国']: counter[word] += 1 print(counter)输出:Counter({'我': 2, '中国': 2, '是': 1, '人': 1...原创 2019-08-01 09:57:23 · 215 阅读 · 0 评论 -
AC自动机字符串匹配——python代码实现
import ahocorasickdef build_actree(wordlist): actree = ahocorasick.Automaton() for index, word in enumerate(wordlist): actree.add_word(word, (index, word)) actree.make_automato...原创 2019-06-11 23:13:40 · 3395 阅读 · 1 评论 -
pandas小技巧
1、更改列的数据类型①一列:pd.to_numeric(s)②多列:df[['a','b']] = df[['a','b']].apply(pd.to_numeric)2、将DataFrame中数据进行标签编码,实现与sklearn.processing.LabelEncoder相同的效果In[3]: pd.Categorical(['a', 'c', 'b',...原创 2018-07-03 21:08:51 · 357 阅读 · 0 评论 -
centos相关
1、监视NVIDIA的GPU使用情况$ watch -n 0.1 nvidia-smi每0.1s显示一次显存情况2、查找文件路径# 查找文件find / -name [file]# 查找文件夹find / -name [path] -type d# 查找内容find . | xargs grep -ri [content]# 只显示文件名称//find ....原创 2019-05-22 18:02:50 · 157 阅读 · 0 评论 -
json相关
1、将dict写入json文件(可成功写入中文)with codecs.open(r'state_urls.json', 'w', 'utf-8') as f: # type(state_urls) = dict f.write(json.dumps(state_urls, ensure_ascii=False)) print('state_urls写入成功!')...原创 2019-04-15 15:14:24 · 226 阅读 · 0 评论 -
xpath小技巧
1、选择当前节点下部分节点如:获取http://www.stats.gov.cn/tjsj/tjbz/tjyqhdmhcxhfdm/2018/11/01/01/110101001.html的“统计用区划代码”和“城乡分类代码”两列内容xpath = '//tr[@class="villagetr"]/td/preceding-sibling::*[1]/text()'获取http...原创 2019-04-14 21:34:08 · 300 阅读 · 0 评论 -
Pytorch使用小技巧
1、nn.Conv2d默认padding为'valid',如何设置为'same'?使用公式计算:o = output p = padding k = kernel_size s = stride d = dilationo = [i + 2*p - k - (k-1)*(d-1)]/s + 1参考网址:https://discuss.pytorch.org/t/how-...原创 2019-04-06 22:24:39 · 215 阅读 · 0 评论 -
pycharm快捷键
1、代码规范化:Ctrl+Alt+L2、函数加注释(insert docstring):将光标移在函数名或类名上,Alt+Enter,选中“Insert docstring”3、保存文件:Ctrl+S新建py文件自动生成注释、时间、作者:File-Settings-Editor-File and Code Templates-Python Script效果:...原创 2019-04-06 11:27:04 · 446 阅读 · 0 评论 -
eclipse pydev自动加辅助信息
1、新建py文件时自动加上创建时间、作者https://blog.csdn.net/wenyusuran/article/details/253824972、为函数自动加上参数注解create docstring功能将光标移至函数名上,快捷键:Ctrl+1。在弹出的浮窗中选择”Make docstring”。按Enter应用该功能。...转载 2019-03-23 20:47:23 · 326 阅读 · 0 评论 -
函数——python
函数不定长参数加了星号(*)的变量名会存放所有未命名的变量参数。加了(**)会存放所有命名的变量参数示例def test(a,b,c,*tup_args,**dict_args): print(a) print(b) print(c) print(tup_args) print(dict_args)test(1,2,3,'a1','a2...原创 2019-03-16 22:34:14 · 210 阅读 · 0 评论 -
python文件读写
mode带'b'的表示二进制格式1、rb以二进制格式打开一个文件。当读取图片或进行文本传输时,需要转换为二进制格式。# mode='rb'# 'aaa.txt'内容为'我是一只猪猪侠'f = open('aaa.txt', mode='rb')content = f.read()print(content, type(content))f.close()输出:...原创 2019-03-22 22:56:42 · 265 阅读 · 0 评论 -
pip默认镜像地址
pip默认镜像地址:https://pypi.org/simple修改pip默认镜像源后,有的包可能只有默认源有。临时使用默认源安装:pip install [module] -ihttps://pypi.org/simple...原创 2019-03-19 17:47:30 · 27045 阅读 · 3 评论 -
数据不平衡:下采样、上采样python代码实现
一、下采样所有数据存在DataFrame对象df中。数据分为两类:多数类别和少数类别,数据量相差大。数据预处理已将多数类别的Label标记为1,少数类别的Label标记为0。从多数类中随机抽取样本(抽取的样本数量与少数类别样本量一致)从而减少多数类别样本数据,使数据达到平衡的方式。import numpy as npimport pandas as pddef lower_sam...原创 2018-09-29 16:02:17 · 24357 阅读 · 2 评论 -
数据结构与算法LeetCode刷题(Python)
参考资料:1、《面试算法LeetCode刷题班》 - 小象学院2、csujedihy / lc-all-solutions一、链表 1. 链表的必备知识要点(包括基础知识、刷题中使用的STL等知识) 2. 链表逆序(LeetCode 92 ,206. Reverse Linked List 1,2) 3. 求两个链表的交点(LeetCod...原创 2018-10-07 11:59:37 · 1761 阅读 · 0 评论 -
梯度下降法python+numpy实现
批量梯度下降法(Batch Gradient Descent, BGD):使用所有样本在当前点的梯度值来对变量参数进行更新操作。随机梯度下降法(Stochastic Gradient Descent, SGD):在更新变量参数的时候,选取一个样本的梯度值来更新参数。小批量梯度下降法(Mini-batch Gradient Descent, MBGD):集合BGD和SGD的特性,从原...原创 2018-10-11 16:28:05 · 2743 阅读 · 1 评论 -
pip install pyltp报错解决办法
报错一:error: Microsoft Visual C++ 14.0 is required. Get it with “Microsoft Visual C++ Build Tools”: http://landinghub.visualstudio.com/visual-cpp-build-tools笔者安装Microsoft Visual C++ 14.0后,依然不能顺利安装pyltp,...原创 2018-07-06 21:35:20 · 5195 阅读 · 3 评论 -
字符处理
1、判断是否为汉字:char = '我'print((char >= u'\u4e00') and (char <= u'\u9fa5'))输出:True原创 2019-08-01 10:56:24 · 248 阅读 · 0 评论