随笔分类 -  python基础

摘要:生成配置文件 $jupyter notebook --generate-config 会返回一个存放jupyter_notebook_config.py的路径 生成密码 打开ipython,创建一个密文的密码: [root@datanode1 ~]# ipython In [1]: from not 阅读全文
posted @ 2022-12-24 15:56 Guang'Jun 阅读(74) 评论(0) 推荐(0) 编辑
摘要:torch.manual_seed(seed) # 为CPU设置随机种子 torch.cuda.manual_seed(seed) # 为当前GPU设置随机种子 torch.cuda.manual_seed_all(seed) # if you are using multi-GPU,为所有GPU设 阅读全文
posted @ 2021-11-19 00:28 Guang'Jun 阅读(278) 评论(0) 推荐(0) 编辑
摘要:假如输入数据是4维的 a = torch.randn(3, 4, 5, 6) y = a[..., 0] # 取第四个维度的第0个 上面操作等同于 y = a[:, :, :, 0] 阅读全文
posted @ 2021-06-11 11:27 Guang'Jun 阅读(53) 评论(0) 推荐(0) 编辑
摘要:#复制文件: shutil.copyfile("oldfile","newfile") #oldfile和newfile都只能是文件 shutil.copy("oldfile","newfile") #oldfile只能是文件,newfile可以是文件,也可以是目标目录 #复制文件夹: shutil 阅读全文
posted @ 2021-05-28 14:29 Guang'Jun 阅读(156) 评论(0) 推荐(0) 编辑
摘要:# 加载数据成字典(读) with open(annotations_file, "r") as fa: annotations = json.load(fa) # 上载数据成序列(写) with open("annotation/train_annotation.json", 'w') as fp 阅读全文
posted @ 2021-05-28 10:58 Guang'Jun 阅读(38) 评论(0) 推荐(0) 编辑
摘要:举例说明: 1. 对于列表,字典的解包 # *取列表,元组元素 ls = [1, 2, 3, 4] print(*ls) # **取字典值 dic = {"key1": 1, "key2": 2} print('{key1}, {key2}'.format(**dic)) [注意]:使用**解包时必 阅读全文
posted @ 2021-05-26 10:37 Guang'Jun 阅读(132) 评论(0) 推荐(0) 编辑
摘要:1. 随机选择 使用random包 从列表里随机选出一个元素 from random import choice ls = [1, 2, 3, 4] print(choice(ls)) 2. 随机抽样 从列表里随机抽出出一组元素,不放回抽样 import random ls = [1, 2, 3, 阅读全文
posted @ 2021-05-25 12:41 Guang'Jun 阅读(142) 评论(0) 推荐(0) 编辑
摘要:原文链接:https://www.runoob.com/python/att-string-format.html 阅读全文
posted @ 2021-05-15 13:30 Guang'Jun 阅读(36) 评论(0) 推荐(0) 编辑
摘要:![image](https://img2020.cnblogs.com/blog/2199011/202105/2199011-20210515111855809-369266290.png) 阅读全文
posted @ 2021-05-15 11:19 Guang'Jun 阅读(20) 评论(0) 推荐(0) 编辑
摘要:解决方法 angle = torch.where(torch.isnan(angle), torch.full_like(angle, 0), angle) print(torch.any(torch.isnan(angle))) torch.where(condition, x, y) 参数1;判 阅读全文
posted @ 2021-05-14 23:07 Guang'Jun 阅读(1642) 评论(0) 推荐(0) 编辑
摘要:当子类与父类存在相同的函数名时,子类的函数就会重写父类的函数。 如果还是想用父类的函数,可以通过super函数强制调用父类函数。但是当子类与父类存在相同的函数名时,子类的函数仍会重写父类的函数。 验证结论1: class A(): def __init__(self): pass def print 阅读全文
posted @ 2021-04-29 01:35 Guang'Jun 阅读(121) 评论(0) 推荐(1) 编辑
摘要:python中reduce 与map的用法 reduce的工作过程是: 在迭代sequence(tuple ,list ,dictionary, string等可迭代物)的过程中, 首先把前两个元素传给 函数参数,函数加工后, 然后把得到的结果和第三个元素作为两个参数传给函数参数, 函数加工后得到的 阅读全文
posted @ 2021-03-26 22:20 Guang'Jun 阅读(102) 评论(0) 推荐(0) 编辑
摘要:Pytorch :list, numpy.array, torch.Tensor 格式相互转化 同时解决 ValueError:only one element tensors can be converted to Python scalars 问题 - torch.Tensor 转 numpy 阅读全文
posted @ 2021-03-17 19:43 Guang'Jun 阅读(1044) 评论(0) 推荐(0) 编辑
摘要:使用方法: from abc import abstractmethod 1.含abstractmethod的方法由子类的相同函数重写 举例: from abc import abstractmethod class BaseModel(object): def __init__(self): se 阅读全文
posted @ 2021-03-11 20:52 Guang'Jun 阅读(155) 评论(0) 推荐(0) 编辑
摘要:class Foo(): def __init__(self, x): print("this is class of Foo.") print("Foo类属性初始化") self.f = "foo" print(x) class Children(Foo): def __init__(self): 阅读全文
posted @ 2021-03-07 21:47 Guang'Jun 阅读(2509) 评论(0) 推荐(0) 编辑
摘要:将一个文件夹变成了一个包 可以通过文件夹名.函数调用__init__.py里的函数 例如: -文件夹(net) -py文件(__init__.py) -py文件(main.py) 文件存储格式如上所示 __init__.py def get(): return 0 main.py from net 阅读全文
posted @ 2021-03-04 21:33 Guang'Jun 阅读(116) 评论(0) 推荐(0) 编辑
摘要:conda create --name python2 python=2.7 ##创建一个新的python环境,python版本为2.7,环境名称为python2 conda info -e ##显示已创建的环境,会列出所有的环境名和对应路径 conda activate python2 ##切换到 阅读全文
posted @ 2021-01-22 21:14 Guang'Jun 阅读(199) 评论(0) 推荐(0) 编辑
摘要:size计算矩阵中所有元素的个数; .shape返回维度值,返回一个元组 len()可以想象成数据长度/条数,即数据的行数 输入: a = np.array([[1, 2, 3, 4], [1, 2, 3, 4]]) print(len(a)) print(a.size) print(a.shape 阅读全文
posted @ 2021-01-19 15:54 Guang'Jun 阅读(1667) 评论(0) 推荐(0) 编辑
摘要:with open(file, 'r') as f:语句的参数 阅读全文
posted @ 2020-11-28 19:20 Guang'Jun 阅读(66) 评论(0) 推荐(0) 编辑
摘要:打开.npy文件 import pickle # 注意使用rb打开二进制文件 f = open('data/NTU-RGB-D/xsub/train_data.npy','rb') data = pickle.load(f) print(data) 打开.npy文件 test=np.load('da 阅读全文
posted @ 2020-11-03 00:02 Guang'Jun 阅读(873) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示
主题色彩
主题色彩