![](https://img-blog.csdnimg.cn/2021082218205151.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
Python基础知识
python基础知识笔记
深度菜鸡-达闻西
这个作者很懒,什么都没留下…
展开
-
python区别之 sort和sorted
sort 与 sorted 区别:1、sort 是应用在 list 上的方法,sorted 可以对所有可迭代的对象进行排序操作。2、list 的 sort 方法返回的是对已经存在的列表进行操作,而内建函数 sorted 方法返回的是一个新的 list,而不是在原来的基础上进行的操作。...原创 2021-09-10 10:32:33 · 88 阅读 · 0 评论 -
函数装饰器
'''函数装饰器'''import timedef time1(func): def new_num(): t1=time.perf_counter() func() t2 = time.perf_counter() print('耗费时长为:%ss' % (t1 - t2)) return new_num@time1def num(): for i in range(10): pr原创 2021-09-06 15:36:14 · 73 阅读 · 0 评论 -
Numpy的相关操作
参考链接: https://www.runoob.com/numpy/numpy-array-from-numerical-ranges.html.numpy相关操作数组属性创建数组可以使用array函数函数function创建numpy.arangenumpy.linspace打印数组数组属性创建数组可以使用array函数从常规的Python列表和元组创造数组。所创建的数组类型由原序...原创 2020-04-02 20:15:27 · 180 阅读 · 0 评论 -
得到数据的标签等相关信息 label
通过图像的名字,得到标签的东西等信息。import torchimport torchvisionfrom torchvision import datasets,transformsimport osimage_datasets = datasets.ImageFolder(r'F:\Python 工程\market 1501\Market-1501-v15.09.15\pytorch\val')print(image_datasets)dataloader = torch.utils.原创 2020-07-03 10:33:05 · 224 阅读 · 0 评论 -
@staticmethod 函数使用
@staticmethod 返回函数的静态方法静态方法可以实例化调用也可以不实例化调用下面举个例子:class school(): @staticmethod def student (num): print('student num is %s !'%num)if __name__ =='__main__': school.student(1000)# 不用实例化也可以调用函数 print('*'*10) HD = sc原创 2020-07-06 16:18:01 · 628 阅读 · 0 评论 -
python 中 list,numpy,tensor的互相转换
import torchimport numpy as npprint('##########建立 a-list;; b-numpy;; c- tensor##########')a = [1,2,3,4,5]b = np.array([1,2,3,4,5])c = torch.arange(1,6)print('a-list:',a,'\n', 'b-ndarray:',b,'\n', 'c-tensor:',c,c.type())print('\n######原创 2020-07-02 16:11:46 · 7835 阅读 · 0 评论 -
LeeCode-回文数
给你一个整数 x ,如果 x 是一个回文整数,返回 true ;否则,返回 false 。回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数。例如,121 是回文,而 123 不是。示例 1:输入:x = 121输出:true示例 2:输入:x = -121输出:false解释:从左向右读, 为 -121 。 从右向左读, 为 121- 。因此它不是一个回文数。示例 3:输入:x = 10输出:false解释:从右向左读, 为 01 。因此它不是一个回文数。示例 4:输原创 2021-08-01 20:02:20 · 79 阅读 · 0 评论 -
LeeCode-整数翻转
目录一、题目链接二、题目介绍三、程序四、重点内容4.1 join()用法4.2 列表的基础用法4.2.1 翻转一、题目链接https://leetcode-cn.com/problems/reverse-integer.二、题目介绍给你一个 32 位的有符号整数 x ,返回将 x 中的数字部分反转后的结果。如果反转后整数超过 32 位的有符号整数的范围 [−231, 231 − 1] ,就返回 0。假设环境不允许存储 64 位整数(有符号或无符号)。示例 1:输入:x = 123输出:3原创 2021-07-31 14:29:51 · 91 阅读 · 0 评论 -
顺序运行.py
原创 2021-03-08 20:55:59 · 134 阅读 · 0 评论 -
添加时间
import timenow_time = time.strftime('%Y/%m/%d/--%H:%M:%S',time.localtime(time.time()))print("训练程序于 %s 跑完."%now_time)原创 2021-03-07 21:09:22 · 157 阅读 · 0 评论 -
ModelCheckpoint()
在这里插入图片描述原创 2020-12-01 17:40:55 · 298 阅读 · 0 评论 -
Yaml 相关基础操作
创建一个文件# 简介name: AnJingage: 18profession: name: 软件测试工程师 pay: 2Kskill: - name1: 接口测试 pay: 1K - name2: 功能测试 pay: 2K读取# coding:utf-8import yaml# 直接打开读出来f = open(r'E:\app\Interface\name.yaml','r',encoding='utf原创 2020-11-30 16:13:45 · 185 阅读 · 0 评论 -
python中的path.isdir()
1 os.listdir() 是返回一个绝对路径下的目录列表import ospath = 'C:/Users/MR-LI/Desktop/program practice'for i in os.listdir(path): print (i)输出了这个路径下的目录文件(输出结果)22 os.path.isdir() 判断对象是否为目录(这个地方一开始弄错了,后来发现 并不是...原创 2020-01-04 09:57:22 · 860 阅读 · 0 评论 -
NotImplementedError raise NotImplementedError NotImplementedError
raise NotImplementedErrorNotImplementedError出现这个错误,说明写的类没有被实现,我的原因是 :class ()def ()super() def forward():def forward()没有和类对齐,如此愚蠢的错误,下次不能再犯了原创 2020-11-16 14:54:49 · 1658 阅读 · 1 评论 -
AttributeError: ‘torch.return_types.max‘ object has no attribute ‘shape‘
测试程序有一句出现了bug,以前没见过,就是正常使用,不觉得会有错。import torchb = torch.range(1,12,1).reshape([3,2,2])print(b,b.shape)d = torch.max(b,dim=0,keepdim=True)###bug所在print(d,d.shape)网上查了一下,torch.max()返回是个turtle,包含了 value,index,所以错误原因也找到了,没有定义index的变量。修改后如下:import to原创 2020-11-13 10:37:48 · 9428 阅读 · 4 评论 -
Python 迭代器、生成器和装饰器 简要学习
目录一、简介二、迭代器1、可迭代对象2、迭代器三、生成器四、 装饰器1、 什么是装饰器一、简介迭代是python的强大功能之一,是访问集合元素的一种方式。迭代器是一个可以记住遍历位置的对象,,在遍历字符串、列表、或者元组的时候非常有用。生成器是函数中包含yield语句的一类特殊函数。装饰器的灵活性很强,可以为一个对象添加新的功能,或者给函数插入相关的功能。二、迭代器1、可迭代对象给定一个list或者tuple,可以通过for循环来遍历这个list或者tuple,这种遍历称为迭代(Itera原创 2020-11-06 13:32:34 · 682 阅读 · 1 评论