随笔分类 -  Python 语言

1
摘要:参考: https://www.cnblogs.com/xuqiang7/p/11082729.html https://docs.python.org/zh-cn/3/library/re.html + 验证数字的正则表达式集 + 验证数字:^[0-9]*$ + 验证n位的数字:^\d{n}$ + 阅读全文
posted @ 2022-11-18 10:36 Gelthin 阅读(130) 评论(0) 推荐(0)
摘要:https://stackoverflow.com/questions/17246260/python-readlines-usage-and-efficient-practice-for-reading https://stackoverflow.com/questions/28538388/py 阅读全文
posted @ 2021-12-14 22:31 Gelthin 阅读(182) 评论(0) 推荐(0)
摘要:# 来自 CAL 代码 # Main Run = ExptPeerRegC10CAL( {"--is_train": True, # why 居然可以这么写? "--is_plot_results": False, "--is_class_resolved": False, "--is_load": 阅读全文
posted @ 2021-04-30 21:55 Gelthin 阅读(162) 评论(0) 推荐(0)
摘要:转自 https://blog.csdn.net/mao_jonah/article/details/89502380 许多Python项目中都包含了requirements.txt文件,该文件记录了当前程序的所有依赖包及其精确版本号。 生成requirement.txt文件 pip freeze 阅读全文
posted @ 2021-01-26 21:24 Gelthin 阅读(11707) 评论(0) 推荐(0)
摘要:利用重定向功能,print 输出可以保存到 txt 如何将array保存到txt文件中?如何将存到txt文件中的数据读出为ndarray类型? 需求:科学计算中,往往需要将运算结果(array类型)保存到本地,以便进行后续的数据分析。 解决:直接用numpy中的方法。 numpy.savetxt(f 阅读全文
posted @ 2020-12-15 16:18 Gelthin 阅读(274) 评论(0) 推荐(0)
摘要:一般而言,可以按照如下方式固定随机数种子,以便复现实验: # 来自相关于 GCN 代码: 例如 grand.py 等的代码 parser.add_argument('--seed', type=int, default=42, help='Random seed.') np.random.seed( 阅读全文
posted @ 2020-11-25 11:03 Gelthin 阅读(1068) 评论(0) 推荐(0)
摘要:dict.get(key, default=None) 用法如下:https://www.runoob.com/python/att-dictionary-get.html key -- 字典中要查找的键。 default -- 如果指定键的值不存在时,返回该默认值。 如下代码相当于 C++ 的 s 阅读全文
posted @ 2020-11-24 11:30 Gelthin 阅读(327) 评论(0) 推荐(0)
摘要:PEP8 PEP8 编码规范中文版 PEP257 文档字符串的规范 【代码注释方案】 参照 https://github.com/DropEdge/DropEdge/blob/master/src/layers.py stub code (桩代码) https://www.zhihu.com/que 阅读全文
posted @ 2020-11-22 22:10 Gelthin 阅读(560) 评论(0) 推荐(0)
摘要:在一些情况下,程序运行产生如下结果,然后进程自动终止,导致这一结果的原因很有可能是内存爆炸。 当两个较大的 (e.g., 10000*10000 维)ndarray 做运算(加法,or 乘法)时,很容易出现这样的结果. linux 系统下,使用 top 命令,可以很容易地看到内存(%MEM) 的使用 阅读全文
posted @ 2020-11-08 11:43 Gelthin 阅读(2902) 评论(0) 推荐(0)
摘要:python2 没有控制循环变量的变量名的作用域,致使同名变量冲突了,这在 python3 中已经修复。 使用了相同的变量名,导致先前的变量指向了另一个变量,导致错误。来自 DIEN 代码 ... uid = self.source_dicts[0][ss[1]] if ss[1] in self. 阅读全文
posted @ 2020-07-21 15:51 Gelthin 阅读(163) 评论(0) 推荐(0)
摘要:from __future__ import absolute_import from __future__ import division from __future__ import print_function 一个file 中出现了这些语句,但是这些语句前面有注释(关于这个文件的说明)。 然 阅读全文
posted @ 2020-07-06 18:37 Gelthin 阅读(150) 评论(0) 推荐(0)
摘要:之前使用学校的云服务器,主要是用 winscp + xshell + 本地 spyder 使用 最近 2020.7.4 准备换用 pycharm, 因为 pycharm 可以直接连接远程服务器,直接调试代码。 pycharm 有学生免费版 https://www.jetbrains.com/comm 阅读全文
posted @ 2020-07-06 09:37 Gelthin 阅读(289) 评论(0) 推荐(0)
摘要:eval() function 将字符串转化为 python 可运行的表达式 https://www.jianshu.com/p/753aba694cf5 Definition: eval(source: Union[Text, bytes, CodeType], globals: Optional 阅读全文
posted @ 2020-07-02 10:41 Gelthin 阅读(338) 评论(0) 推荐(0)
摘要:1.保存图片时设置 pad_inches 去掉周围空白部分 在保持图片时,设置 bbox_inches 为 tight 可以去掉图片周围的空白部分。这一命令广为人知 但若是在插图到论文,想要进一步放大图片,以便更清晰,还可以进一步使得图片的空白部分更少: 这里 pad_inches 相当于在图片元素 阅读全文
posted @ 2020-01-15 10:36 Gelthin 阅读(575) 评论(0) 推荐(0)
摘要:with open(r'./record.pkl', 'rb') as inp: res = [] try: res.append(pickle.load(inp)) except: noise_labels, true_labels = res[-2:] 有 bug, 但未测出来。 代码来源于 p 阅读全文
posted @ 2020-01-05 11:41 Gelthin 阅读(248) 评论(0) 推荐(0)
摘要:1. 大幅度提升 Pytorch 的训练速度 device = torch.device("cuda" if torch.cuda.is_available() else "cpu") torch.backends.cudnn.benchmark = True 但加了这一行,似乎运行结果可能会存在细 阅读全文
posted @ 2020-01-04 09:35 Gelthin 阅读(1903) 评论(0) 推荐(0)
摘要:dtype 可用于查看数据类型 astype 可用于修改数据类型,不过并非就地修改 astype 可以相当于 np.int(), np.float() 用 dtype 修改数据类型,会出现 bug, dtype 更像是以另一种方式来解读2进制串 阅读全文
posted @ 2019-12-29 17:55 Gelthin 阅读(697) 评论(0) 推荐(0)
摘要:参考 https://blog.csdn.net/weixin_42401701/article/details/80820778 和 https://www.cnblogs.com/lllcccddd/p/10661966.html 一些相关的命令 conda update -n base con 阅读全文
posted @ 2019-11-26 22:49 Gelthin 阅读(5256) 评论(0) 推荐(0)
摘要:python 中要动态生成一系列变量名,要写一个程序,让 a1=1,a2=2,… a100=100通常类似于matlab 中,可以使用 eval,但是实际上根本不需要这种危险的东西,因为Python的变量名就是一个字典的key而已。 要获取这个字典,直接用 locals 和 globals 函数即可 阅读全文
posted @ 2018-09-28 16:06 Gelthin 阅读(8852) 评论(1) 推荐(2)
摘要:希望生成一系列不同精度的 Naive Bayes 分类器,故需要保存多个这样的算法模型。 在python 语言中,可以用字典来保存 算法模型 import copy ##需要对模型进行 copy,故要 copy 模块 print('生成') for i in np.arange(0,100): y_ 阅读全文
posted @ 2018-09-28 09:46 Gelthin 阅读(815) 评论(0) 推荐(0)

1