python官方帮助文档大全(简体中文版):https://docs.python.org/zh-cn/3.7/library/argparse.html
目录
1、python argparse 用法总结:
可以参考文章:python argparse 用法总结(https://www.jianshu.com/p/a41fbd4919f8),写的非常详细
import argparse :首先导入模块
parser = argparse.ArgumentParser(description=“your script description”) :创建一个解析对象,description 参数可以用于插入描述脚本用途的信息,可以为空
parser.add_argument() :向该对象中添加你要关注的命令行参数和选项
parser.parse_args() :进行解析
位置参数:
可选参数:
type:
default:
choices:
help:
action:
以上几个参数的功能在文章:python argparse 用法总结(https://www.jianshu.com/p/a41fbd4919f8)中都有详细解释和示例
代码示例:
import argparse
parser = argparse.ArgumentParser(description="calculate X to the power of Y")
parser.add_argument(
"square", type=int, help="display a square of a given number")
parser.add_argument(
"-v",
"--verbosity",
type=int,
choices=[0, 1, 2],
default=1,
help="increase output verbosity")
args = parser.parse_args()
answer = args.square**2
if args.verbosity == 2:
print("the square of {} equals {}".format(args.square, answer))
elif args.verbosity == 1:
print("{}^2 == {}".format(args.square, answer))
else:
print(answer)
测试结果如下
2、add_argument函数的metavar参数:
add_argument函数的metavar参数(https://www.pynote.net/archives/2119)
用来使 ‘-h’、’–help’ 打印帮助信息的时候,显示的信息更好看一点
3、numpy.inf:
python中numpy中有关 inf 的处理技巧(https://www.jianshu.com/p/dfbadf23850d)
用 inf 表示无穷大,方便理解和表示
>>> np.NINF
-inf
>>> np.inf
inf
>>> np.log(0)
-inf
>>> np.array([1,2])/0 #碰到的最多的情况
array([ inf, inf])
4、Python str.join方法:拼接字符串:
Python str.join方法:拼接字符串(https://blog.csdn.net/TCatTime/article/details/85254896)
>>> a = '!@'.join(['Fusion', 'Sphere', 'Cloud'])
>>> a
'Fusion!@Sphere!@Cloud'
5、pytorch 中 checkpoint(检查点)是什么意思:
tensorflow中的检查点checkpoint详解(二)——以tensorflow1.x 的模型保存与恢复为主(https://blog.csdn.net/qq_27825451/article/details/105819752)
pytorch checkpoint_[日常] PyTorch 预训练模型,保存,读取和更新模型参数以及多 GPU 训练模型(https://blog.csdn.net/weixin_39639698/article/details/110517562)
Checkpoints文件是一个二进制文件,存储的是神经网络中各个参数的值,并没有网络结构信息
6、python print函数之end:
python print函数之end(https://www.cnblogs.com/znh8/p/9310225.html)
print函数默认换行,是end=’\n’在起作用,如果不想换行可以用 print(xxx,end=’’)
>>> for i in range(10):
print(i,end='')
>>> 0123456789
>>>
>>> for i in range(10):
print(i,end='**') #不换行,结尾后追加**
>>> 0**1**2**3**4**5**6**7**8**9**
7、pytorch—之cudnn.benchmark:
pytorch—之cudnn.benchmark和cudnn.deterministic(https://blog.csdn.net/zxyhhjs2017/article/details/91348108)
torch.backends.cudnn.benchmark = True,可以增加程序的运行效率