随笔分类 -  python

Python打印args命令行参数
摘要:import argparse parser = argparse.ArgumentParser() parser.add_argument('--epochs', type=int, default=1000) parser.add_argument('--batch_size', type=in 阅读全文

posted @ 2022-07-26 22:00 那抹阳光1994 阅读(916) 评论(1) 推荐(0) 编辑

python列表映射元素替换
摘要:有时我们会遇到将list中的元素替换为另一组元素的情况,此时可以采用列表映射进行快速元素替换。 例如: a = [2, 3, 4, 5, 0, 1] 需要将元素顺序替换为编号0, 1, 2, 3, 4, 5,此时就可以采用列表映射的方式。 # 通过列表映射进行元素替换a = [2, 3, 4, 5, 阅读全文

posted @ 2022-04-03 23:46 那抹阳光1994 阅读(689) 评论(0) 推荐(0) 编辑

matplotlib绘图常用命令汇总
摘要:常规绘图流程 import numpy as np import matplotlib import matplotlib.pyplot as plt # 关于matplotlib绘图Times New Roman字体问题 # https://blog.csdn.net/Limonor/articl 阅读全文

posted @ 2021-11-24 21:32 那抹阳光1994 阅读(329) 评论(0) 推荐(0) 编辑

numpy以追加模式保存数据至txt
摘要:with open(save_path + '\data.txt', 'a+') as f: np.savetxt(f, data) 阅读全文

posted @ 2021-09-26 16:12 那抹阳光1994 阅读(1106) 评论(0) 推荐(1) 编辑

Python matplotlib画图时图例说明(legend)放到图像外侧详解
摘要:Python matplotlib画图时图例说明(legend)放到图像外侧详解 阅读全文

posted @ 2021-07-04 21:28 那抹阳光1994 阅读(470) 评论(0) 推荐(0) 编辑

pycharm下使用matpltlib绘图复用figure无法更新画布问题
摘要:发现pycharm下使用matpltlib绘图重复使用一个figure无法对画布内容进行更新。 plt.draw()方法用于更新绘制的内容,但是pycharm中没反应。 解决方法: import matplotlib as mpl #mpl.use('Agg') # non-GUI backend 阅读全文

posted @ 2021-05-10 09:12 那抹阳光1994 阅读(805) 评论(0) 推荐(0) 编辑

pyharm AttributeError: module 'xxxx' has no attribute 'xxxx'
摘要:pyharm AttributeError: module 'xxxx' has no attribute 'xxxx' 发现自己犯了一个错误,就是自己新建的python文件名字和内置的函数名冲突,修改了python文件的名字就可以正常运行无报错了。 阅读全文

posted @ 2021-03-19 20:58 那抹阳光1994 阅读(46) 评论(0) 推荐(0) 编辑

numpy切片索引后维度的变化
摘要:对一个numpy数组或矩阵做切片索引,例如对一列或一行数据进行提取。如果索引值是标量,索引后的量维度减小1。如果索引是一个范围如a:b,则索引后维度不变。 a = np.random.rand(4, 5) a Out[13]: array([[0.83451584, 0.27220378, 0.84 阅读全文

posted @ 2020-12-09 19:15 那抹阳光1994 阅读(1050) 评论(1) 推荐(0) 编辑

AttributeError: cannot assign module before Module.__init__() call
摘要:https://stackoverflow.com/questions/43080583/attributeerror-cannot-assign-module-before-module-init-call 没有对继承的父类的属性进行初始化。 阅读全文

posted @ 2020-11-09 19:17 那抹阳光1994 阅读(2613) 评论(0) 推荐(0) 编辑

记MongoDB的安装
摘要:在我的win10系统下可以正常安装MongoDB官网的msi文件,但为我的另一台安装时却报告以下错误: service 'mongodb server' failed to start. verify that you have sufficient privileges to start syst 阅读全文

posted @ 2020-06-27 15:48 那抹阳光1994 阅读(149) 评论(0) 推荐(0) 编辑

Python格式化输出指定宽度及占位符
摘要:1 '{:08}'.format(11) 2 3 4 5 mat = "{:020}\t{:028}\t{:032}" 6 print(mat.format(1,2, 3)) 冒号后面指定输出宽度,:后的0表示用0占位。 out: 1 '00000011' 2 3 4 Name:Aviad Age: 阅读全文

posted @ 2020-06-25 19:00 那抹阳光1994 阅读(6919) 评论(0) 推荐(0) 编辑

Python3 中的map
摘要:最近看一段Python2写的代码,有一句: torch.FloatTensor(map(lambda x: x['values'], data)) Python3下运行后报错: TypeError: new(): data must be a sequence (got map) 我的data明明是 阅读全文

posted @ 2020-06-16 21:42 那抹阳光1994 阅读(1941) 评论(0) 推荐(0) 编辑

sklearn之分类模型混淆矩阵和分类报告(转载)
摘要:机器学习中的分类问题评估模型性能时,往往需要计算各种评价指标。通过计算混淆矩阵(confusion matrix)可以方便地导出各种指标,例如precision(查准率)、recall(tpr)(查全率、召回)、accuracy、fpr、F1分数、Roc曲线、Auc等。 一些常用的分类评价指标计算公 阅读全文

posted @ 2020-06-10 18:34 那抹阳光1994 阅读(3453) 评论(0) 推荐(0) 编辑

Python中的有序字典--OrderedDict
摘要:Python拥有一些内置的数据类型,比如str, int, list, tuple, dict等, collections模块在这些内置数据类型的基础上,提供了几个额外的数据类型: namedtuple(): 生成可以使用名字来访问元素内容的tuple子类 deque: 双端队列,可以快速的从另外一 阅读全文

posted @ 2020-06-03 13:58 那抹阳光1994 阅读(1619) 评论(0) 推荐(0) 编辑

计算wasserstein距离
摘要:import numpy as np from scipy.stats import wasserstein_distance p = [0,5,9] q = [2,5,7] w = wasserstein_distance(q,p) print(w) 阅读全文

posted @ 2020-06-02 21:17 那抹阳光1994 阅读(2254) 评论(0) 推荐(0) 编辑

python中的super().__init__()
摘要:子类构造函数调用super().init() class Person: def __init__(self, name = 'Person'): self.name = name class Puple(Person): # 直接继承Person,可调用name pass class Puple_ 阅读全文

posted @ 2020-05-15 16:11 那抹阳光1994 阅读(6031) 评论(0) 推荐(0) 编辑

概率分布之间的距离度量以及python实现(四)
摘要:1、f 散度(f-divergence) KL-divergence 的坏处在于它是无界的。事实上KL-divergence 属于更广泛的 f-divergence 中的一种。 如果P和Q被定义成空间中的两个概率分布,则f散度被定义为: 一些通用的散度,如KL-divergence, Helling 阅读全文

posted @ 2019-09-27 10:22 那抹阳光1994 阅读(1341) 评论(0) 推荐(0) 编辑

概率分布之间的距离度量以及python实现(三)
摘要:转自:https://www.cnblogs.com/denny402/p/7050779.html 概率分布之间的距离,顾名思义,度量两组样本分布之间的距离 。 1、卡方检验 统计学上的χ2统计量,由于它最初是由英国统计学家Karl Pearson在1900年首次提出的,因此也称之为Pearson 阅读全文

posted @ 2019-09-27 10:21 那抹阳光1994 阅读(603) 评论(0) 推荐(0) 编辑

距离度量以及python实现(二)
摘要:转自:https://www.cnblogs.com/denny402/p/7028832.html 接上一篇:http://www.cnblogs.com/denny402/p/7027954.html 7. 夹角余弦(Cosine) 也可以叫余弦相似度。 几何中夹角余弦可用来衡量两个向量方向的差 阅读全文

posted @ 2019-09-27 10:20 那抹阳光1994 阅读(217) 评论(0) 推荐(0) 编辑

机器学习博客推荐
摘要:https://github.com/mainkoon81?tab=overview&from=2018-10-01&to=2018-10-31 阅读全文

posted @ 2019-09-25 10:01 那抹阳光1994 阅读(185) 评论(0) 推荐(0) 编辑

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示