![](https://img-blog.csdnimg.cn/20201014180756913.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
Python使用
文章平均质量分 63
Python和一些常见库的使用
love1005lin
自律及自由
展开
-
Python添加源
已Windows 系统下为例子(Linux添加方式不同)在cmd中输入以下命令自动添加清华源(选择其他源只需要把网址换掉就可以)。pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple会自动生成pip.ini的文件,放在下边的目录:完成!...原创 2022-01-19 13:17:45 · 1649 阅读 · 0 评论 -
随机数种子(seed)
在科学技术和机器学习等其他算法相关任务中,我们经常需要用到随机数,为了把握随机数的生成特性,从随机数的随机无序中获得确定和秩序。我们可以利用随机数种子(random seed)来实现这一目标,随机数种子,可以使得引入了随机数的整个程序,在多次运行中得到确定的,一致的结果。1. 随机数种子python自带的random函数:import random# print(help(random))def test_random_seed_in_std_lib(seed=0, cnt...原创 2021-12-27 15:06:26 · 19640 阅读 · 0 评论 -
解决:AttributeError: ‘dict_items‘ object has no attribute ‘copy‘
在使用 XGBoost 的过程中遇到如下问题:**AttributeError: ‘dict_items’ object has no attribute ‘copy’ **源代码:from sklearn.datasets import load_irisimport xgboost as xgbfrom xgboost import plot_importancefrom matplotlib import pyplot as pltfrom sklearn.model_selection原创 2021-05-15 19:27:45 · 1186 阅读 · 0 评论 -
plt.tight_layout()
plt.tight_layout()tight_layout会自动调整子图参数,使之填充整个图像区域。这是个实验特性,可能在一些情况下不工作。它仅仅检查坐标轴标签、刻度标签以及标题的部分。当你拥有多个子图时,你会经常看到不同轴域的标签叠在一起。plt.rcParams['savefig.facecolor'] = "0.8"def example_plot(ax, fontsize=12): ax.plot([1, 2]) ax.locator_params(nbins=3)原创 2021-05-12 10:12:26 · 8300 阅读 · 0 评论 -
Python中argparse模块的使用
Python argparse模块argparse 模块的作用:直接使用命令行与python进行交互, 是用来处理命令行参数的库。(不需要安装,直接调用 )argparse 使用简化成四个步骤:1:import argparse2:parser = argparse.ArgumentParser()3:parser.add_argument()4:parser.parse_args()上面四个步骤解释如下:首先导入该模块;然后创建一个解析对象;然后向该对象中添加你要关注的命令行参数和选项,每一原创 2021-04-30 14:17:52 · 1503 阅读 · 1 评论 -
Python中 -m 的使用和原理
Python -m 的使用和原理在使用命令行Python时,有很多的使用选项:使用python --help来查看:usage: python [option] … [-c cmd | -m mod | file | -] [arg] …本文想要聊聊比较特殊的“-m”选项:关于它的典型用法、原理解析与发展演变的过程。-m mod run library module as a script (terminates option list)"mod"是“module”的缩写,即“-m”原创 2021-04-30 12:48:47 · 2616 阅读 · 8 评论 -
Pytorch单机多卡训练
pytorch中单机多卡可以使用DataParallel和DistributedDataParallel 来实现。pytorch官网中推荐使用DistributedDataParallel。两者区别是:DataParallel是单进程多线程控制GPU的实现方式,因此只能在一台机器上使用,而DistributedDataParallel则是多进程控制GPU,除了能实现单机多卡外,也能够实现分布式训练。DataParallel一般会比DistributedDataParallel慢Distributed原创 2021-04-26 21:20:45 · 1003 阅读 · 0 评论